predicatebuilder

Difference between PredicateBuilder<True> and PredicateBuilder<False>?

半城伤御伤魂 提交于 2020-08-24 05:32:10
问题 I have the code: var predicate = PredicateBuilder.True<Value>(); predicate = predicate.And(x => x.value1 == "1"); predicate = predicate.And(x => x.value2 == "2"); var vals = Value.AsExpandable().Where(predicate).ToList(); If I have PredicateBuilder.True<Value>() , it brings back what I expect, but if I have PredicateBuilder.False<Value>() , it brings back 0 records. Can someone explain what the the difference is and why in one scenario I get back 0 records an in the other I get what I expect.

Difference between PredicateBuilder<True> and PredicateBuilder<False>?

我只是一个虾纸丫 提交于 2020-08-24 05:30:06
问题 I have the code: var predicate = PredicateBuilder.True<Value>(); predicate = predicate.And(x => x.value1 == "1"); predicate = predicate.And(x => x.value2 == "2"); var vals = Value.AsExpandable().Where(predicate).ToList(); If I have PredicateBuilder.True<Value>() , it brings back what I expect, but if I have PredicateBuilder.False<Value>() , it brings back 0 records. Can someone explain what the the difference is and why in one scenario I get back 0 records an in the other I get what I expect.

Building dynamic lambda predicate with short date

瘦欲@ 提交于 2020-01-24 19:50:27
问题 I have the following code that helps me build a lambda expression via reflection. However when I try to compare versus a Date it converts my value to a full DateTime stamp. How can I get it to build my predicate so it will only compare the short date? System.Reflection.PropertyInfo propInfo = typeof(T).GetProperty(property); Type propertyType = propInfo.PropertyType; if (Utilities.IsNullableType(propertyType)) { propertyType = Nullable.GetUnderlyingType(propertyType); } ParameterExpression

predicate builder with two tables

家住魔仙堡 提交于 2020-01-13 05:13:07
问题 A Party can have one or more Contact objects. I want to select all Parties who's streetname contains a specific keyword. If I just want to search in Party I can use the code below. But how do I extend it to also search in Contact ? public IQueryable<Party> SearchParties(List<string> keywords) { var predicate = PredicateBuilder.False<Party>(); foreach (string word in keywords) { var keyword = word; predicate = predicate.Or(p => p.surname.Contains(keyword)); predicate = predicate.Or(p => p

Combine And/Or with PredicateBuilder?

╄→гoц情女王★ 提交于 2020-01-07 03:39:09
问题 I have a list of Ids and I only want to do an AND on the first one and and OR on the subsequent ones. In the past, I have kept a counter variable and when the counter is 1, I do the And , but after that I do an OR , but I was curious if there was an easier way: foreach(string id in Ids) { predicate.And(x=> id.Contains(x.id)); //I want to do an And only on the first id. } This is what I have done in the past, but is there a more concise way: int counter = 1; foreach (var Id in Ids) { string i

Can PredicateBuilder generate predicates that span multiple tables?

半世苍凉 提交于 2019-12-30 09:00:11
问题 I would like to dynamically generate predicates that span multiple tables across a Join in a Linq statement. In the following code snippet, I want to use PredicateBuilder or a similar construct to replace the 'where' statement in the following code: Replace: public class Foo { public int FooId; // PK public string Name; } public class Bar { public int BarId; // PK public string Description; public int FooId; // FK to Foo.PK } void Test() { IQueryable<Foo> fooQuery = null; // Stubbed out

Entity Framework and Predicate Builder - Predicates being Ignored in SQL Query

☆樱花仙子☆ 提交于 2019-12-24 01:29:28
问题 I'm having a problem with EF and Predicate Builder. I've been through all the instructions and I'm pretty sure I'm doing everything right, but when I run SQL Profiler and inspect the query going to the database, it's ignoring my predicates and getting every record in the table, and this table is currently up to about 600,000 rows so it slows things down a little. My predicates then get applied after the database has queried. Can someone please tell me what I'm missing? var predicate =

PredicateBuilder: OR condition nested inside .And()

我怕爱的太早我们不能终老 提交于 2019-12-23 02:32:41
问题 I'm using PredicateBuilder to build a query against a List of Umbraco Nodes to filter search results. I have the searched ID value coming through as a String via the QueryString which I then compare to a string field on each of the Umbraco Nodes in the list to get matches. Currently, the code does the match against the target field in there is a value in the Query String which works fine. I need to add a conditional inside my .And() that tries to match the QS against the field String if the

How do I dynamically construct a predicate method from an expression tree?

廉价感情. 提交于 2019-12-22 00:19:06
问题 Here's the scenario: Silverlight 4.0, DataGrid, PagedCollectionView itemssource. The objective is to apply a Filter to the PCV. The filter needs to be a Predicate<object>(Method) - where Method implements some logic against the object and returns true/false for inclusion. What I have is a need to optionally include 3 different criteria in the filter logic and explicit code quickly gets ugly. We don't want that, do we? So I see that there is a way to build an expression tree using

Linq PredicateBuilder with conditional AND, OR and NOT filters

北城以北 提交于 2019-12-20 10:55:40
问题 We have a project using LINQ to SQL, for which I need to rewrite a couple of search pages to allow the client to select whether they wish to perform an and or an or search. I though about redoing the LINQ queries using PredicateBuilder and have got this working pretty well I think. I effectively have a class containing my predicates, e.g.: internal static Expression<Func<Job, bool>> Description(string term) { return p => p.Description.Contains(term); } To perform the search i'm doing this