An Entity with Key (PK) will not round-trip

c# entity-framework

Question

I have two tables: <subjects> and <prerequisites>. The primary key of prerequisite table is a composite key: pr_subject_id and pr_prerequisite_subject_id . They are both foreign keys from the <subjects> table. I can map the pr_subject_id in a association but i can't map the return trip (pr_prerequisite_subject_id). See image. How should i solve this?

note: When i made the associations in sql server it was fine but when i loaded the database in the entity framework, the entity framework dropped the prerequisite table because of this return trip association.

enter image description here

enter image description here

1
0
5/23/2013 6:20:37 AM

Accepted Answer

I looked around but i think this is a common problem with the Entity Framework. I found two workarounds here. Basically what i did was adding a third column er_id and let that be the primary key. Then to enforce that there will be no double of the other two columns i added a unique constraint.

3
5/23/2013 7:06:26 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow