Entity Framework combine lambda expressions from different entities

c# entity-framework entity-framework-6 expression lambda

Popular Answer

You may implement an interface with a predicate function as long as you have control over the way these classes are created.

For instance:

public interface ITestable
{
    Func<string, bool> Predicate { get; }
}

public class Admission : ITestable
{
    // ...other members...

    public Person Person { get; }

    public Expression<Func<string, bool>> Predicate =>
        x => Person.Predicate(x);
}

public class Person : ITestable
{
    // ...other members...

    public Expression<Func<string, bool>> Predicate =>
        x => string.IsNullOrEmpty(x) || FirstName.Contains(x) || LastName.Contains(x);
}

// The calling code:
IQueryable<ITestable> people =
    source.Where(x => x.Predicate(searchTerm));
0
5/12/2017 3:54:18 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow