c# - Refactoring Func<T> into Expression<Func<T>> -
I have a method that currently serves as a parameter for Func & lt; Product, string & gt;
, but I get this a expression & lt; Funky & lt; Product, string & gt; & Gt; Must be
. Using AdWords Works, here is an example of what I would like to do using funk.
I want to see it like this:
Private static zero doSomethingWithExpression (expression & lt; Func & lt; product, string & gt; ; My expression) {{AdWordsWorldDataContext DB = New AdWords WorksDateText ()) using {var result = DB. Products Group by (product => new {sub-category name = my exposure (product), product name = product, product report}}; }}
However, the problem I am running is that myExpression (product)
is invalid (will not be compiled). After reading some other posts, I understand why and if it needs a product
variable for the second part of my key, then I might say something like this:
var results = db.Products.GroupBy (myExpression);
But I need the product
variable because I need a second part of the key (product number). So I'm not sure what to do now. I can not leave it in the form of bluff because problems arise because I can not understand how the expression can be used because I do not think how can I pass it to the product
variable. Any ideas?
Edit: How would I tell the example of this method:
DoSomethingWithFunc (product => product.productsSubcategory name);
There is no way of dividing the expression tree, which is the expression and Is depicted as a lieutenant; T & gt;
Object in the middle of "Tree literal" presented by Lambda expression. You must create an expression tree to pass manually from GroupBy
:
// Type of type requires a clearly named type () Private Sector ResultType {public string sub-category name {get; Set; } {Receive public int productionंबर; Set; } | } Private Static Zero DoSomethingWithExpression (Expression & lt; Func & lt; Products, String & gt; My Expressions) {var productParam = Expression Parameter (type (product), "product"); Expression (Expression.memberinit (expression.new (type (result type)), expression.bine (type (as a result) .Getproperty ("sub-namename"), expression expression (myxpression, productParam), expression.bind (typef ( Result Type) .GetProperty ("Production"), Expression Property (ProductPime, "Production"), Product); (AdWords WorksDateContact DB = New AdWareDateTextNext ()). Industry while (var result = DB. Products. Group by (Grupakspr);}}
Comments
Post a Comment