EF4 db-first: how to add missing relationships

情到浓时终转凉″ 提交于 2019-12-11 06:09:59

问题


I am using db-first to creating object model for a readonly database, but some relationships are not automatically picked up. For example in Foo.BarId is not automatically connected to Bar object. If I click on BarId property, I don't see anything to associate it to a Bar in the context menu or properties window. How can I manually claim foreign keys without messing up anything?


回答1:


Figured out myself... here are the steps:

(On model designer)

  1. Delete BarId property from Foo entity.
  2. Right click Foo entity (not any of its properties), add association between Foo and Bar.
  3. Click the association arrow.
  4. In Mapping Details window, add "Foo" table.
  5. Map Foo.Id to Foo.Id, map Bar.Id to Foo.BarId.

Done.




回答2:


Make sure that both tables have primary keys and Bar table has foreign key defined.



来源:https://stackoverflow.com/questions/12468351/ef4-db-first-how-to-add-missing-relationships

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!