score:3
Have you tried ILSpy? It even has some options to control if you want to produce LINQ "function" syntax or from... where
syntax (View->Options->Decompiler->Decompile query expression
and Decompile anonymous methods/lambdas
)
For your other question: SubFunctionEntity.get_Volume
is the getter of the property Volume
of the class SubFunctionEntity
.
(MethodInfo) methodof(SubFunctionEntity.get_Volume)
is the same as typeof(SubFunctionEntity).GetProperty("Volume").GetGetMethod()
, only done at compile time instead that at runtime. The problem is that C# doesn't have a methodof
"function".
If you really want to use what the Reflector gave you, this is the "corrected" version:
public double? LoadSumRialAmount(long functionId, long? subFunctionId)
{
ParameterExpression expression;
if (!subFunctionId.HasValue)
{
return (from func in base.MetaData.SubFunction
where func.FunctionId == functionId
select func).Select<SubFunctionEntity, double?>(Expression.Lambda<Func<SubFunctionEntity, double?>>(Expression.Multiply(Expression.Property(expression = Expression.Parameter(typeof(SubFunctionEntity), "func"), typeof(SubFunctionEntity).GetProperty("Volume").GetGetMethod()), Expression.Property(expression, typeof(SubFunctionEntity).GetProperty("RialAmount").GetGetMethod())), new ParameterExpression[] { expression })).Sum();
}
return (from func in base.MetaData.SubFunction
where (func.FunctionId == functionId) && (func.SubFunctionId != subFunctionId)
select func).Select<SubFunctionEntity, double?>(Expression.Lambda<Func<SubFunctionEntity, double?>>(Expression.Multiply(Expression.Property(expression = Expression.Parameter(typeof(SubFunctionEntity), "func"), typeof(SubFunctionEntity).GetProperty("Volume").GetGetMethod()), Expression.Property(expression, typeof(SubFunctionEntity).GetProperty("RialAmount").GetGetMethod())), new ParameterExpression[] { expression })).Sum();
}
Note that you'll need some using:
using System.Linq;
using System.Linq.Expressions;
Ah... the most complex expression is : func => (func.Volume * func.RialAmount)
so you could write the method as:
public double? LoadSumRialAmount(long functionId, long? subFunctionId)
{
if (!subFunctionId.HasValue)
{
return (from func in base.MetaData.SubFunction
where func.FunctionId == functionId
select func).Select(func => (func.Volume * func.RialAmount)).Sum();
}
return (from func in base.MetaData.SubFunction
where (func.FunctionId == functionId) && (func.SubFunctionId != subFunctionId)
select func).Select(func => (func.Volume * func.RialAmount)).Sum();
}
Addendum: checked, the ILSpy produce random garbage similar-but different to Reflector
Source: stackoverflow.com
Related Articles
- Reflector generated Lambda Expression, how to get back back actual Linq Query?
- Selecting multiple columns with linq query and lambda expression
- C# multiple variables in lambda expression inside LinQ query
- How to insert a lambda into a Linq declarative query expression
- Lambda Expression LINQ Equivalent to SQL Exists Query on Same Table/Variable
- Deeper level LINQ query in a lambda expression
- Convert this Linq query from query syntax to lambda expression
- Using LINQ to query an IDictionary with Lambda expression
- Convert lambda expression to linq query
- Convert SQL Query back to Linq Expression programmatically
- C# lambda expression in LINQ query
- How to convert this LEFT JOIN Linq Query to Lambda expression
- Linq Query to Lambda Expression
- Unreachable expression code in LINQ query
- Convert linq query to lambda expression
- How to write a LINQ query or Lambda expression on one to many relation with filter
- C# Linq Lambda Expression for Entity Framework Query Passing Custom Expression to Where Condition
- MVC4 - Linq Lambda expression to query multiple association tables
- How to Convert this Linq Query into Lambda Expression
- How can I make this SQL query work in LINQ lambda expression
- How to LINQ Query Code First generated EF6 hierarchical entities (entities within entities)?
- How to restructure Linq query to avoid using Contains() inside an Any() lambda expression (need a ContainsAll())
- How to substitute the LINQ Query with lambda expression
- A LINQ question: map query expression to c# code
- How to write this linq query using Lambda expression
- How to convert this SQL query to LINQ or Lambda expression in C#?
- C# Pass lambda expression field into method and use field in linq query
- Convert this SQL Query to a Linq Lambda Expression
- Using Lambda expression from a separate class in SELECT clause of LINQ query c# Projection
- The entity or complex type cannot be constructed in a LINQ to Entities query - using lambda expression
- Linq Data Source WhereParameters with "\" in value
- getting at a deep property for a lambda Expression
- ASP.NET MVC LINQ Entity Framework recursive
- Ling to Entity Convert Null or Empty to Int
- How I get with a attribute value from a xml the other attribute values from the same node?
- How can I run a paged query in EF Core if Skip and Take are always evaluated locally?
- Perform an OR of two LINQ IQueryables
- Got error, "Some part of your SQL statement is nested too deeply" only on some servers
- How do you deal with sequences of IDisposable using LINQ?
- ASP WebApi GET response with string id?
- Split collection into groups of different sizes
- DataGrid: Adding DataGridCellInfo-instances to the DataGrid.SelectedCells-collection is very slow
- Check if a string is sorted
- linq group by where count
- LEFT OUTER JOIN in Linq - How to Force
- How to resolve Entity Framework Unable to create a constant value of type in a query involving navigation properties?
- Extending DbFunctions in Entity Framework Core?
- Format JSON collection string by JavaScript or Linq
- LINQ expression using a previously defined variable
- VB.NET LINQ query disregarding string casing