Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Entity Framework on a Database Undefined Foreign Key Relationships

For a variety of reasons the database that I'm working on (SQL Server 2005) doesn't have any relationships defined. Every table has a primary key. And most tables have at least one foreign key, however we've never configured the constraints.

Can anyone tell me the steps that I should take to inform Entity Framework of the underlying relationships between tables? Is there a particular document that describes this process?

like image 560
zorlack Avatar asked May 10 '26 15:05

zorlack


1 Answers

You will need to manually create the associations between the tables in your EF model.

In the Entity Framework designer surface, you basically right-click on your table and from the context menu, you need to choose the "Add -> Association" option. In the dialog box that pops up, you can establish the association between your two tables - even without foreign key relationship in the underlying database.

Marc

like image 199
marc_s Avatar answered May 13 '26 04:05

marc_s



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!