开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜