开发者

Is there a built in way to avoid magic strings with the Entity Framework's Include()? [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

Entity Framework Include() strongly typed

Ok, I've got an ent开发者_JAVA技巧ity 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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜