I am trying to use a specification template implemented as a Linq expression so that Linq providers can parse it to create efficient database queries.
This gives a basic idea.
It's hard for me to try to get it to work with parent / child request
class Parent
{
public int Foo;
public IList<Child> Children = new List<Child>();
}
class Child
{
public int Bar;
}
class Program
{
static void Main(string[] args)
{
IQueryable<Parent> qry = GetQry();
var parentsWithBigChildBars =
from parents in qry
where parents.Children.Any(child => child.Bar > 10)
select parents;
var parentsWithBigChildBars2 =
from parents in qry
where parents.Children.Any( ?? )
select parents;
}
public Expression<Func<Child, bool>> IsBigBar()
{
return child => child.Bar > 10;
}
public Func<Child, bool> IsBigBar2()
{
return child => child.Bar > 10;
}
}
source
share