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?
Cheers
Tim
A: No.
B: You cannot.
EF is able to use relations only when they point to primary key so either change
Usertable to useUserIDas primary key and removeUserGuidor changeUserCustomFieldtable to pointUserIDtoUserGuidin theUsertable.The reason why it doesn’t work is that your database requires
UserIDinUsertable to be marked as unique (that means unique constraint) and EF doesn’t support unique constraints yet.