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?
Asked
Active
Viewed 2,289 times
2 Answers
2
Figured out myself... here are the steps:
(On model designer)
- Delete BarId property from Foo entity.
- Right click Foo entity (not any of its properties), add association between Foo and Bar.
- Click the association arrow.
- In Mapping Details window, add "Foo" table.
- Map Foo.Id to Foo.Id, map Bar.Id to Foo.BarId.
Done.

NS.X.
- 2,072
- 5
- 28
- 55
0
Make sure that both tables have primary keys and Bar table has foreign key defined.

Bishnu Paudel
- 2,083
- 1
- 21
- 39
-
The database is readonly. Is there a way to fix it on the model? – NS.X. Sep 18 '12 at 05:24
-
It could be possible to fix in the model but you will run into a problem when saving/updating the entities in the database. Anyway,it's possible to establish a relation by using association in model designer. Just right click on the designer, Add -> Association and setup the association between these entities. – Bishnu Paudel Sep 18 '12 at 05:57