views:

210

answers:

1

Hi all,

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 possible, or am I stuck with include.include.include.include?

Thanks

A: 

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.

Thomas
Thanks for the link, I had scan read that post previously and couldnt see anything that helped. Just read it properly and looks like exactly what I need.Thanks!
JamesStuddart