Creating a list of .Include() in linq to entities
I have a long list of includes:
.Include("x")
.Include("y")
.Include("z")
.Include("z.w")
.Include("z.v")
I would like to use this list on three different queries. How can I put these in开发者_如何学运维 a list and use that list in all my queries in order to not repeat myself.
Try:
public static class MyQueryHelpers
{
public static ObjectQuery<Foo> MyIncludes(this ObjectQuery<Foo> query)
{
return query.Include("x")
.Include("y")
.Include("z")
.Include("z.w")
.Include("z.v");
}
}
Now use it:
var q = from f in Context.Foos.MyIncludes()
select f;
精彩评论