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?

  • Which is better, Using multiple column in GROUP BY or GROUP BY with AGGREGATE?
  • “Streaming” read of over 10 million rows from a table in SQL Server
  • How to write a file to disk and insert a database record in a single transaction?
  • How to set encoding parameter for SQL Server Bulk statement?
  • Sql Query Select From an update, records, that were not updated
  • Recursive function in sql server 2005?
  • Cheers

  • Sending data from excel to Server using HTTP Post
  • Populating Html.DropDownList with foreign key table vlaues
  • How to update data as upper case first letter with t-sql command?
  • Code First Migrations and Stored Procedures
  • How to retrieve one record from SQL Server database in MVC Model
  • Cannot find the object “QueryNotificationErrorsQueue” because it does not exist or you do not have permissions
  • One Solution collect form web for “EF5 How to Add missing Relationships”

    A: No.
    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 UserID to UserGuid in the User table.

    The reason why it doesn’t work is that your database requires UserID in User table to be marked as unique (that means unique constraint) and EF doesn’t support unique constraints yet.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.