views:

25

answers:

1

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.

+4  A: 

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;
Craig Stuntz