开发者

Lazy Loading with EntityFramework, named Foreign Key Relationship?

If you are using EntityFrameworks and Lazy Loading your Foreign Key objects, is there any way to change the "named instance" of the Foreign Key?

Example: A table called Account with 2 Foreign Keys to Contact. One for EmergencyContactID and one for开发者_运维知识库 Manager. When we use Lazy Loading in our app the code would look like this:

myAccount.Contact.Name = "Bob";  
myAccount.Contact1.Name = "John";

What I WANT to happen is this:

myAccount.EmergencyContact.Name = "Bob";
myAccount.Manager.Name = "John";

Is this possible to do? The key being, is this possible to do without manually changing the auto-generated .edmx file every time it is regenerated? (there is an annoying habit on our team of completely deleting and regenerating the edmx if a single field name changes on any table).


You just need to change the name of the navigation property in the edmx designer. Navigation properties are listed at the bottom of the entity, under the rest of the fields.

You shouldn't be deleting and recreating the edmx every time...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜