Bridge table with no primary key

2.4k Views Asked by At

I have a bridge table in my database design and it does not have a primary key. When I try to use the database first approach for ASP.NET MVC 3 to create my model, it creates a model with a warning saying "The table/view 'CRM_Test_1.dbo.SalesOrderProduct' does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it."

Am I doing something wrong or is there a way to make this warning go away??

Thanks.

2

There are 2 best solutions below

1
On BEST ANSWER

You could add a primary key (int, autonumber) if you want to suppress the error message. Some would say that you NEED a primary key. Or you could make a compound key of the bridged ids, if that makes sense in your data model.

0
On

Entity Framework uses the Primary key to create the unique Entity Key for each record. If there is no primary key on the table it does display a warning that you see.

Its not wrong per say. But you could add an identity column to the table as the primary key. This will make the warning go away.