linqkit

IQueryable<T> with EntityObject using Generics & Interfaces (Possible?)

大憨熊 提交于 2019-12-01 11:27:39
问题 I have a search repository for EntityFramework 4.0 using LinqKit with the following search function: public IQueryable<T> Search<T>(Expression<Func<T, bool>> predicate) where T : EntityObject { return _unitOfWork.ObjectSet<T>().AsExpandable().Where(predicate); } And another class which uses the IQueryable return value to subset the query in ways that are not possible using the Boolean LinqKit PredicateBuilder expressions: public IQueryable<T> SubsetByUser<T>(IQueryable<T> set, User user)

LinqKit PredicateBuilder returns all or non rows

China☆狼群 提交于 2019-11-30 08:41:37
问题 I'm beginning to use LinqKit's PredicateBuilder to create predicate's with OR conditions which is not possible with Linq expressions. The problem I'm facing is if I begin with PredicateBuilder.True<MyEntity>() it returns all rows and if I begin with PredicateBuilder.False<MyEntity>() it returns non rows , apart from what expressions I use! look at the code below: var pre = PredicateBuilder.True<MyEntity>(); pre.And(m => m.IsActive == true); using (var db = new TestEntities()) { var list = db

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

依然范特西╮ 提交于 2019-11-29 21:06:43
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 = requestingUserId, Body = ( msg.RootMessage == null ) ? msg.Body : msg.RootMessage.Body, Title = ( ( msg.RootMessage ==

LinqKit PredicateBuilder returns all or non rows

梦想与她 提交于 2019-11-29 07:16:33
I'm beginning to use LinqKit 's PredicateBuilder to create predicate's with OR conditions which is not possible with Linq expressions. The problem I'm facing is if I begin with PredicateBuilder.True<MyEntity>() it returns all rows and if I begin with PredicateBuilder.False<MyEntity>() it returns non rows , apart from what expressions I use! look at the code below: var pre = PredicateBuilder.True<MyEntity>(); pre.And(m => m.IsActive == true); using (var db = new TestEntities()) { var list = db.MyEntity.AsExpandable().Where(pre).ToList(); dataGridView1.DataSource = list; } It should return the

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

落花浮王杯 提交于 2019-11-28 06:54:20
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 code throws System.InvalidCastException: Unable to cast object of type 'System.Linq.Expressions

Howto use predicates in LINQ to Entities for Entity Framework objects

醉酒当歌 提交于 2019-11-27 21:12:32
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 getting the exception [System.NotSupportedException] --- {"The LINQ expression node type 'Invoke' is not