Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework - DB-First - Composite Foreign Keys

I have a database that has a table with a 2-column primary composite key (one int, one bigint.) I have two tables that have a composite foreign key, referencing the first table's composite primary key. The relationships are (as far as I know,) fine and dandy on the database itself.

When generating a DB context via DB-first EF6, these relationships/navigation properties are not represented in the generated models (No virtual members in the two child tables referencing the parent table.)

Since it's db-first, I can't modify the models.

like image 783
Bryan Morgan Avatar asked May 21 '15 16:05

Bryan Morgan


1 Answers

In this case you can put those relationships into the onmodelcreating function in db context. We can put constraint there.

like image 132
Pavvy Avatar answered Oct 13 '22 06:10

Pavvy