Sunday, 15 July 2012

c# - Converting Linq MemberExpression lambda to work on class with reference -


For this question, I have a standard structure of the product (with an inactive flag) and order items ). I also have a query builder, which generates Linq Expressions used to query the products. A sample filter allows a user to search for active / inactive products, such as a Linq expression that generates:

  expression & lt; Func & lt; Product, bool & gt; & Gt; TestProductActive = Product = & gt; ! Product.IsActive;  

I want to take that expression and use it IQueryable & lt; OrderItem & gt; I will call it expression.Invoke with in-store archives:

  public static expression & lt; Func & lt; TDestination, TResult & gt; & Gt; (TDSART, TRSULTA & gt; DTSARS, TRSUATAT & FTC & lt; TDSTINATION, TSOSA & gt; RESOURCES FORM FORM DESTINATION) {PARAMETER EXPRESSION Para = Expression. Parameter (typef (TDSTINATION), "ARG"); Expression is called GETSource = Expression.Invoke (getSourceFromDestination, Ultimate); Expression was called OriginBody = expression. Invoke (@ this, invocatedGetSource); Expression & lt; Funk & lt; TDSTINATION, TRASHTTT & gt; & Gt; Result = expression. Lambda & lt; Funk & lt; TDestination, TResult & gt; & Gt; (InvokedOriginalBody, Ultimate); Return result; }  

Which calls I will call:

  Expression & lt; Funk & lt; Order itam, bull & gt; & Gt; TestOrderItemProductActive = testProductActive.Translate & lt; Product, OrderItem, bool & gt; (OrderItem => orderItem.Product);  

But NHibernate.Linq (and I have seen in the question, Linq to Entities) does not support the expression. Invoke .

Is there a way to take member expression from testProductActive and call it ! OrderItem.Product.IsActive ? Turn on


? Example of real life, I have expression and lieutenant; Function & lt; Product, bull & gt; & Gt; will be the view of expression which will be required to convert all. I have now got my filter to generate expression for both types of records, but I would love to leave the repetition and do this by changing the code of a filter Without a different type of record can be used.

This is not a very similar vein in the form of your proposal, but


No comments:

Post a Comment