开发者

Entity framework using Data Repository pattern - DeepLoading

I have been implementing a new project which I have decided to use the repository pattern and Entity Framework.

I have sucessfuly implemented basic CRUD methods and I have no moved onto my DeepLoads.

From all the examples and documentation I can find to do this I need to call something like this:

public Foo DeepLoadFoo()
{
    return (from foobah in Context.Items.Include("bah").Include("foo").Include("foofoo") select foo).Single();
}

This doesnt work for me, maybe I am trying to be too lazy but what I would like to achieve would be something along the lines of this:

public Foo DeepLoadFoo(Foo entity, Type[] childTypes)
{
    return (from foobah in Context.Items.Include(childTypes).Single();
}

Is anything like this po开发者_JS百科ssible, or am I stuck with include.include.include.include?

Thanks


This blog post mentions that the Entity Framework ObjectContext has all the metadata about entities and their properties. So maybe you can use that metadata to walk the properties of your entity, and their child properties, etc.

In other words, I believe you should be able to use the metadata to automatically compose Include calls on your query.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜