Usage
- Refrence LinqExpressionProjection.dll and add using:
using LinqExpressionProjection.Test.Model;
- Define your projection expression of type Expression<Func<TIn, TOut>>:
private Expression<Func<Project, double>> averageAreaSelector = p => p.Subprojects.Average(p => p.Area);
- In query, call AsExpressionProjectable() on collection and Project<TOut>() on the expression:
var projects = (from p in ctx.Projects.
AsExpressionProjectable() select new
{
Project = p,
AverageArea = averageAreaSelector.Project<double>()
}).ToArray();
Make sure the selection expression <TIn> is of the same type as the projection (Select() call) lambda parameter