Search code examples
asp.net-mvc-3entity-frameworkdatabase-firstef-database-first

Bridge table with no primary key


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.


Solution

  • 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.