linqkit

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.

Use LinqKit PredicateBuilder for related model (EF Core)

℡╲_俬逩灬. 提交于 2020-01-01 09:12:20
问题 I want to use LinqKit's PredicateBuilder and pass the predicate into .Any method for related model. So I want to build a predicate: var castCondition = PredicateBuilder.New<CastInfo>(true); if (movies != null && movies.Length > 0) { castCondition = castCondition.And(c => movies.Contains(c.MovieId)); } if (roleType > 0) { castCondition = castCondition.And(c => c.RoleId == roleType); } And then use it to filter model that has relation to model in predicate: IQueryable<Name> result = _context

Is there a particular reason LinqKit's expander can't pick up Expressions from fields?

那年仲夏 提交于 2019-12-29 11:34:17
问题 I'm using LinqKit library which allows combining expressions on the fly. This is a pure bliss for writing Entity Framewok data acess layer because several expressions can optionally be reused and combined, which allows both for readable and efficient code. Consider following piece of code: private static readonly Expression<Func<Message, int, MessageView>> _selectMessageViewExpr = ( Message msg, int requestingUserId ) => new MessageView { MessageID = msg.ID, RequestingUserID =

LinqKit: AsExpandable not working

冷暖自知 提交于 2019-12-24 00:58:16
问题 Code: public static GetRows() { var to_ret = db.TableRows.Select(x=> new TableRowModel( { TableRowId = x.TableRowId, Type = x.Type, Name = x.Name, CreatedAt = x.CreatedAt, ModifiedAt = x.ModifiedAt, Enums = x.Enums.AsExpandable().Select(y => y.ToEnumModel()) }); return to_ret; } public static EnumModel ToEnumModel(this Enum x) { var to_ret = new EnumModel() { CFPId = x.CFPId, CreatedAt = x.CreatedAt, ModifiedAt = x.ModifiedAt, }; return to_ret; } Running GetRows gives error saying: LINQ to

Adding to Lambda Expression and work with Entity Framework

拥有回忆 提交于 2019-12-22 09:27:02
问题 If I want retrieve more columns with an already existing lambda tree expression like below, how would I do that? This works with Entity Frameworks and want it to still work. Expression<Func<DivisionTeam, DirectorTeamModel>> columns= (d) => new DirectorTeamModel { Id = d.Id, TeamId = d.Team.Id }; if (criteria.Template == ExportTemplate.Import || criteria.Template == ExportTemplate.Default) { // Retrieve additional columns from "columns" expression tree } return _divisionTeamsRepository

Creating a dynamic Linq select clause from Expressions

拟墨画扇 提交于 2019-12-21 05:22:06
问题 Let's say I have defined the following variables: IQueryable<MyClass> myQueryable; Dictionary<string, Expression<Func<MyClass, bool>>> extraFields; // the dictionary is keyed by a field name Now, I want to tack on some dynamic fields to the IQueryable, so that it returns an IQueryable<ExtendedMyClass> , where ExtendedMyClass is defined as: class ExtendedMyClass { public MyClass MyObject {get; set;} public IEnumerable<StringAndBool> ExtraFieldValues {get; set;} } class StringAndBool { public

LinqKit System.InvalidCastException When Invoking method-provided expression on member property

一个人想着一个人 提交于 2019-12-17 18:17:53
问题 Given a simple parent/child class structure. I want to use linqkit to apply a child lambda expression on the parent. I also want the Lambda expression to be provided by a utility method. public class Foo { public Bar Bar { get; set; } } public class Bar { public string Value { get; set; } public static Expression<Func<Bar, bool>> GetLambdaX() { return c => c.Value == "A"; } } ... Expression<Func<Foo, bool>> lx = c => Bar.GetLambdaX().Invoke(c.Bar); Console.WriteLine(lx.Expand()); The above

Howto use predicates in LINQ to Entities for Entity Framework objects

南笙酒味 提交于 2019-12-17 16:14:07
问题 I'm using LINQ to Entities for Entity Framework objects in my Data Access Layer. My goal is to filter as much as I can from the database, without applying filtering logic to in-memory results. For that purpose Business Logic Layer passes a predicate to Data Access Layer. I mean Func<MyEntity, bool> So, if I use this predicate directly, like public IQueryable<MyEntity> GetAllMatchedEntities(Func<MyEntity, Boolean> isMatched) { return qry = _Context.MyEntities.Where(x => isMatched(x)); } I'm

LinqKit Predicate Builder throws TypeLoadException?

丶灬走出姿态 提交于 2019-12-11 02:32:44
问题 I am experiencing a problem while attempting to execute a query that I have built dynamically using PredicateBuilder. I am able to build the query but when executing the query itself I get the following "TypeLoadException"... When running: return context.SearchRecords.AsExpandable().Where(predicate).ToList(); Could not load type 'System.Data.Entity.Infrastructure.IDbAsyncEnumerable`1' from assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. I have