Question

Possible Duplicate:
Entity Framework Include() strongly typed

Ok, I've got an entity framework query where I use Include to tell it I want a related object loaded:

var employees = _entities.Employees.Include("Manager").ToList()

By using include I avoid generating a query for every single employee's manager record (Instead a friendly JOIN is used in the query and the database is never bothered again).

But the use of a magic string "Manager" is unsettling, especially after coming from the supposedly more primitive, quick and dirty Linq2SQL. From a coding stand point it's like a loaded gun, ready to throw a run time exception that should have been caught at compile time. It also puts a big damper on refactoring.

Are there any built in properties or methods to get around this? For example I see Manager.EntityKeyPropertyName as a static string property, but this does not seem to be what I want. I'd rather not manually add a hard coded list of constants somewhere, but it would be better then the naked intellisense blind magic strings.

Was it helpful?

Solution

No there is not any build-in strong typed version of Include in EF 4 (I think it is in EF Features CTP4 and CTP5). I'm using this and I'm quite happy with it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top