My question is illustrated by code sample below. How do I place part of the lambda elsewhere ?
How do I call the 'Foo' from my 'GetGurus()' method ? I want the LINQ to translate it to 1 statement.
public enum GuruLevel
{
NotSet,
Goku,
SuperSayan
}
private IEnumerable<PersonInfo> GetGurus()
{
using (var context = new CRMContext())
{
var persons = context.Person
.Where(p => p.Experience > 10)
.OrderBy(p => p.DateOfBirth)
.Select(p => new PersonInfo())
{
StackOverFlowName = p.StackOverFlowName,
Experience = p.Experience,
GuruStatus = Foo //(p.Experience > 9000) ? GuruLevel.SuperSayan : GuruLevel.Goku
}
return persons.ToList();
}
}
public static System.Linq.Expressions.Expression<Func<Person, GuruLevel>> Foo
{
get
{
return bar => (bar.Experience > 9000) ? GuruLevel.SuperSayan : GuruLevel.Goku;
}
}