score:3
Accepted answer
just set the body to be the second parameter, p2
. you already have the reference.
var p1 = expression.parameter(relationshipitems.elementtype, "i");
var p2 = expression.parameter(instanceentities.elementtype, "o");
var body = p2;
var lambda = expression.lambda(body, p1, p2);
score:0
if, for the sake of example, we assume p1 is an int and p2 is a string then this:
var p1=expression.parameter(typeof(int),"i");
var p2=expression.parameter(typeof(string),"o");
var lambda=expression.lambda(p2,p1,p2);
var function=lambda.compile() as func<int,string,string>;
var result=function(10,"hello");
will generate a function that returns "o". the lambda will return the value in the last expression in its body, which in the above example is just the parameter p2.
Source: stackoverflow.com
Related Query
- What expression method to use to get back parameter?
- How to use a method with an out parameter in a lambda expression
- What is the typeArguments parameter of the Expression.Call Method when making a Expression Tree?
- What is the use of Enumerable.Zip extension method in Linq?
- C# Pass Lambda Expression as Method Parameter
- What are Expression Trees, how do you use them, and why would you use them?
- LINQ: Passing lambda expression as parameter to be executed and returned by method
- Get the parameter value from a Linq Expression
- Expression of type 'System.Int32' cannot be used for parameter of type 'System.Object' of method 'Boolean Equals(System.Object)'
- when and in what scenario to use Expression Tree
- How do I build Expression Call for Any Method with generic parameter
- How to implement method with expression parameter c#
- Get request to api with predicate expression as a parameter
- Is there any extension method which get void returning lambda expression ?
- How can I get back from an un-typed Expression to a typed one?
- Can I use LINQ to get more than 100 records back from a Quickbooks Online ServiceContext?
- Why can't I use a range value's property as a parameter when calling a method in a LINQ query?
- Workaround to use a method within a LINQ expression
- Linq expression to return the first overloaded method that takes 1 string parameter
- LINQ Is it possible to get a method name without a return type via LINQ expression trees?
- c# use string parameter to define what property to filter by in List of objects
- What would it take to create a C# compilation error, when you use custom methods where Expression is expected?
- How to get and use source of grouping in LINQ?
- how to use a method with 2 parameters in my lambda expression
- How to use Lambda expression to replace string parameter
- What should you use for joining in LINQ, Query syntax or method syntax?
- instead of firstordefault what do i use to get all the values
- pass a bool expression as a method parameter
- How to use LINQ to get method name and namespace in a soap request?
- Dynamicaly changing the type of a parameter in an Expression without knowing the target type at code time
More Query from same tag
- how to retrieve rows from database selected from dropdown list in mvc 4
- Datapicker to filter data with date range
- linq select query?
- entity framework returning different result when predicate is passed
- Best strategy for returning large result sets quickly
- How can I get a randomized collection out of linq-to-sql model?
- Linq eager load chain entities
- Linq from XML to Object with one Element ToList<>
- Sum "Amount" from one table and display in Another Table
- LINQ: Create persistable Associations in Code, Without Foreign Key
- C# - Select XML Descendants with Linq
- List.Cast<> error "is a method which is not valid in the given context"
- LINQ return a value IEnumerable
- Dynamically Generating a Linq/Lambda Where Clause
- Using "contains" to query a list <Key-Value> in C#
- where clause with Arraylist in linq
- How to create a collection of Expression<Func<T, TRelated>>?
- Assign DbSet and query result to same variable
- C# Compare one List string with substring of other list string
- Flatten LINQ Collection
- LINQ:How to flatten deep nested objects with LINQ
- linq sql find duplicates but take null and empty string as the same
- Linq to SQL check for null strangeness
- How to get data from a Table if they exist in another Table C# LINQ
- VB.NET Linq Expression with function(x) is not executed?
- C# - Async method in SELECT LINQ operation
- C# Web API LINQ Entity Queries - Cast AnonymousType to Class-Object
- Create a dynamic Expression<Func<TIn, TOut>> from a string
- How do I group a list using Linq
- Running count on a column using linq