Is there any alternative to this:
Organizations.Include("Assets").Where(o => o.Id == id).Single()
I would like to see something like:
Organizations.Include(o => o.Assets).Where(o => o.Id == id).Single()
to avoid the hard-coded string "Assets".
Another solution is to retrieve entity name using EntitySet.Name.
You code will be:
In EF 4.1, there is a built-in extension method for this.
You must have a reference to "EntityFramework" assembly (where EF 4.1 lives) in your project and use System.Data.Entity.
If you want to include nested entities, you do it like this:
Not sure if this works for EF4.0 entities (ObjectContext based).
Another option is to include an internal partial class inside your class using the TT template.
T4 code:
Which will produce something like:
For Entity Framework 1.0, I created some extensions methods for doing this.
Usage:
I haven't tested this on EF4.0, but I expect it to work.
See 'Say goodbye to the hardcoded ObjectQuery(T).Include calls'.
Good news that EF4 CTP4 currently support this feature.