predicatebuilder

Linq PredicateBuilder with conditional AND, OR and NOT filters

懵懂的女人 提交于 2019-12-03 00:40:37
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 (some code omitted for brevity): public Expression<Func<Job, bool>> ToLinqExpression() { var predicates =

Adding Where Condition to All Requests EF6

人盡茶涼 提交于 2019-12-01 20:33:45
问题 Most of my entities (not all) have two properties called CompanyId and Deleted . How would be possible to auto insert these two properties for all select requests instead of setting manually on every single query I have along the whole app. Example: db.MyEntity.Where(me => me.Id == 1).Select(me => me.Description) Check dynamically it the entity has the props CompanyId and Deleted . Case affirmative, transform it like this db.MyEntity.Where(me => me.Id == 1 && Deleted == false && CompanyId ==

Linq partial match in list?

心已入冬 提交于 2019-12-01 20:08:57
I have a list of partial strings that I need to match in a table. I'm using PredicateBuilder. var predicate = PredicateBuilder.False<Name>(); List<string> names = new List<string>(); names.Add("test name"); **<===matches** names.Add("test"); **<=== doesn't match** predicate = predicate.Or(n => names.Contains(n.Company)); var results = (from n in Names .AsExpandable() .Where(predicate) select(new{ n.Company})); n.Company = "test name" This will match if the n.Company is exactly "test name" but it doesn't match if I just use "test". How do I match a partial on a list.Contains? You should change

Linq partial match in list?

不打扰是莪最后的温柔 提交于 2019-12-01 18:55:30
问题 I have a list of partial strings that I need to match in a table. I'm using PredicateBuilder. var predicate = PredicateBuilder.False<Name>(); List<string> names = new List<string>(); names.Add("test name"); **<===matches** names.Add("test"); **<=== doesn't match** predicate = predicate.Or(n => names.Contains(n.Company)); var results = (from n in Names .AsExpandable() .Where(predicate) select(new{ n.Company})); n.Company = "test name" This will match if the n.Company is exactly "test name" but

Using PredicateBuilder with VB.NET

微笑、不失礼 提交于 2019-12-01 12:12:36
I have recreated the Predicatebuilder class in a seperate C# project and I'm trying to use it in a VB.NET project but I keep getting the following error: Overload resolution failed because no accessible 'Or' accepts this number of arguments. when I use it like so: Dim predicate = PredicateBuilder.False(Of t_Quote)() predicate = predicate.Or(Function(q) q.iQuoteType = iQuoteType) The relivant project is referenced, I'm using the correct imports statement and it all compiles without any errors. Any idea where I'm going wrong? Here is the PredicateBuilder class in C# I'm using: public static

Generated SQL with PredicateBuilder, LINQPad and operator ANY

一笑奈何 提交于 2019-12-01 11:14:01
I previously asked a question about chaining conditions in Linq To Entities. Now I use LinqKit and everything works fine. I want to see the generated SQL and after reading this answer , I use LinqPad . This is my statement: var predProduct = PredicateBuilder.True<Product>(); var predColorLanguage = PredicateBuilder.True<ColorLanguage>(); predProduct = predProduct.And(p => p.IsComplete); predColorLanguage = predColorLanguage.And(c => c.IdColorEntity.Products.AsQueryable().Any(expr)); ColorLanguages.Where(predColorLanguage).Dump(); The code works in VS2008, compile and produce the correct result

Generated SQL with PredicateBuilder, LINQPad and operator ANY

南笙酒味 提交于 2019-12-01 09:22:49
问题 I previously asked a question about chaining conditions in Linq To Entities. Now I use LinqKit and everything works fine. I want to see the generated SQL and after reading this answer, I use LinqPad. This is my statement: var predProduct = PredicateBuilder.True<Product>(); var predColorLanguage = PredicateBuilder.True<ColorLanguage>(); predProduct = predProduct.And(p => p.IsComplete); predColorLanguage = predColorLanguage.And(c => c.IdColorEntity.Products.AsQueryable().Any(expr));

How to use predicate builder with linq2sql and OR operator

☆樱花仙子☆ 提交于 2019-12-01 08:58:05
I have two tables (TABLE1, TABLE2 - unique i know) that has a 1-to-many relationship respectively and a foreign key between ID columns of both tables. Using linq2sql I am trying to select all TABLE1 entries such that their corresponding TABLE2 values contains at least 1 item in the list I pass it. Here's some sample code I was using in LINQPad (awesome program) to test it out however am getting the error NotSupportedException: Unsupported overload used for query operator 'Any'. long[] items = { 3, 5, 8 }; var predicate = PredicateBuilder.False<TABLE2>(); foreach (long i in items) { long t = i;

Using PredicateBuilder with VB.NET

喜你入骨 提交于 2019-12-01 08:35:02
问题 I have recreated the Predicatebuilder class in a seperate C# project and I'm trying to use it in a VB.NET project but I keep getting the following error: Overload resolution failed because no accessible 'Or' accepts this number of arguments. when I use it like so: Dim predicate = PredicateBuilder.False(Of t_Quote)() predicate = predicate.Or(Function(q) q.iQuoteType = iQuoteType) The relivant project is referenced, I'm using the correct imports statement and it all compiles without any errors.

How to use predicate builder with linq2sql and OR operator

感情迁移 提交于 2019-12-01 07:12:19
问题 I have two tables (TABLE1, TABLE2 - unique i know) that has a 1-to-many relationship respectively and a foreign key between ID columns of both tables. Using linq2sql I am trying to select all TABLE1 entries such that their corresponding TABLE2 values contains at least 1 item in the list I pass it. Here's some sample code I was using in LINQPad (awesome program) to test it out however am getting the error NotSupportedException: Unsupported overload used for query operator 'Any'. long[] items =