predicatebuilder

Nesting OR using Linq PredicateBuilder

这一生的挚爱 提交于 2019-12-10 11:17:37
问题 I am using predicate builder to write the following code: IEnumerable<int> ids= new List<int> { 47, 48 }; var predicate = PredicateBuilder.False<Customer>(); predicate = predicate.And(x => x.CreatedAt >= fromDate && x.CreatedAt <= toDate); foreach (var id in ids) { predicate = predicate.Or(x => x.Source.Id == id); } var result = Database.Set<Customer>().AsExpandable() .Where(predicate) .ToList(); The SQL generated looks like (just the WHERE clause): WHERE ([Filter6].[SourceId] IN (@p__linq__0

Sitecore Search Predicate Builder multiple keyword search with boosting not working as desired

徘徊边缘 提交于 2019-12-07 00:34:39
问题 I have sitecore pages / lucene documents with the following fields: Title Filename Content File Contents I'm creating a search for these and have the following requirements: Hits containing the whole phrase in the title field should be returned first. Hits containing the whole phrase in the filename field should be returned second. Hits containing the whole phrase in the content should be returned third Hits containing the whole phrase in the file contents should be returned fourth Hits

PredicateBuilder: OR condition nested inside .And()

僤鯓⒐⒋嵵緔 提交于 2019-12-06 16:04:37
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 field has a value, but if the field has no value, then it should match that as well. if (!string

Nesting OR using Linq PredicateBuilder

怎甘沉沦 提交于 2019-12-06 07:59:34
I am using predicate builder to write the following code: IEnumerable<int> ids= new List<int> { 47, 48 }; var predicate = PredicateBuilder.False<Customer>(); predicate = predicate.And(x => x.CreatedAt >= fromDate && x.CreatedAt <= toDate); foreach (var id in ids) { predicate = predicate.Or(x => x.Source.Id == id); } var result = Database.Set<Customer>().AsExpandable() .Where(predicate) .ToList(); The SQL generated looks like (just the WHERE clause): WHERE ([Filter6].[SourceId] IN (@p__linq__0,@p__linq__1)) AND ([Filter6].[CreatedAt] >= @p__linq__2) AND ([Filter6].[CreatedAt] <= @p__linq__3)',

Sitecore Search Predicate Builder multiple keyword search with boosting not working as desired

荒凉一梦 提交于 2019-12-05 05:39:18
I have sitecore pages / lucene documents with the following fields: Title Filename Content File Contents I'm creating a search for these and have the following requirements: Hits containing the whole phrase in the title field should be returned first. Hits containing the whole phrase in the filename field should be returned second. Hits containing the whole phrase in the content should be returned third Hits containing the whole phrase in the file contents should be returned fourth Hits containing all of the keywords (in any order) in the title field should be returned fifth Hits containing

LINQ to SQL PredicateBuilder

▼魔方 西西 提交于 2019-12-04 19:31:08
问题 Im using the PredicateBuilder as seen here http://www.albahari.com/nutshell/predicatebuilder.aspx, everything works great, and now i can genrate Dynamic LINQ to SQL expressions, but the thing that i dont understand is why when i am on a loop like this: var inner = PredicateBuilder.False<MyType>(); foreach (var f in Filtermodel.InstrumentsFilterList.Where(s => s.isActive)) { int temp = f.InstrumentID; inner = inner.Or(ud => ud.InstrumentId == temp); } Why must i use that temp variable?, i try

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

∥☆過路亽.° 提交于 2019-12-04 19:29:39
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 PredicateBuilder and pass that into Linq.Where, a la: IQueryable<Product> SearchProducts (params string[] keywords)

Using PredicateBuilder is there a way to build a predicate off of a variable length list of field names?

◇◆丶佛笑我妖孽 提交于 2019-12-04 13:16:36
问题 I have a list containing a variable number of field names. I would like to do a loop through this list and create a predicate that filters for all records that have a value in the field. foreach (var field in FieldNames) { myPredicate= myPredicate.And(m => m.*field*!=null ); } I'm not sure how to go about doing this. Any suggestions? TIA 回答1: You can only write lambda expressions if you know what the properties are at compile time. Since you clearly don't know what the fields are that you

predicate builder with two tables

白昼怎懂夜的黑 提交于 2019-12-04 13:03:51
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.lastname.Contains(keyword)); predicate = predicate.Or(p => p.number.Contains(keyword)); } return db.Parties

LINQ to SQL PredicateBuilder

∥☆過路亽.° 提交于 2019-12-03 12:25:19
Im using the PredicateBuilder as seen here http://www.albahari.com/nutshell/predicatebuilder.aspx , everything works great, and now i can genrate Dynamic LINQ to SQL expressions, but the thing that i dont understand is why when i am on a loop like this: var inner = PredicateBuilder.False<MyType>(); foreach (var f in Filtermodel.InstrumentsFilterList.Where(s => s.isActive)) { int temp = f.InstrumentID; inner = inner.Or(ud => ud.InstrumentId == temp); } Why must i use that temp variable?, i try to use the "f" iterator variable but it only get the last value on the list for each iteration, like