0

I have no problem generating an .edmx file for an MVC project I am working on. It involves one table and one view. However, EF decides on the primary key, which is actually a unique value each row, but I was hoping to make a text field the primary key because that is what I search on. It has unique values.

Error 6002: The table/view 'DWS.dbo.InventoryTiny' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view. C:\DWS\DWS\DWS.edmx

Read-only is ok. But I would like to change the primary key to a different column. How do I do that and this humble idiot thanks you in advance.

abatishchev
  • 92,232
  • 78
  • 284
  • 421
JustJohn
  • 1,115
  • 2
  • 19
  • 38

1 Answers1

0

Ok, the problem was not in changing the SQL Server table and Views. I can't do that because they are used for other stuff.

But I found a solution that was simple and so far with a restart, has worked. In the designer window for the .edmx file, I right clicked on the column name, and unchecked "Primary Key" choice and went and right clicked on the column that I wanted to use. doh. If it was a snake it would have bit me.

There is/was no code to show. Just the message that EF generator decided to pick a Primary Key on a View. I didn't want the primary key it automatically picked.

Here is where I found the answer: Error 6002: The table/view does not have a primary key defined

thank you stack over flow

Community
  • 1
  • 1
JustJohn
  • 1,115
  • 2
  • 19
  • 38