EF5 How to Add missing Relationships
Hi i have a database first EF5 model defined.
My user table has a primary key guid UserGUID
and another key field UserID with an auto-incrementing integer.
I have created a table called UserCustomField which has
UserID and I have created a foreign key constraint to UserID in my User Table.
When I update the model from the database all foreign key relationships to primary keys are generated but none to Key fields. Ignoring the potential point about using the guid through all my tables…..
A/ shouldn’t EF add this relationship?
B/ how can i manually add it?
One Solution collect form web for “EF5 How to Add missing Relationships”
B: You cannot.
EF is able to use relations only when they point to primary key so either change
User table to use
UserID as primary key and remove
UserGuid or change
UserCustomField table to point
UserGuid in the
The reason why it doesn’t work is that your database requires
User table to be marked as unique (that means unique constraint) and EF doesn’t support unique constraints yet.