문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top