Entity Type has no key defined. Define the key for this entity type.

  • Thread starter Thread starter Can.Do
  • Start date Start date
C

Can.Do

Guest
Using VS 2019 Community, building an MVC application, SQL Server db with entity model. 1st, I was trying to add a database-view to an existing model, VS reported that my view didn't have a primary key -- never heard of a primary key requirement on a view, what are engineers doing at MS? Let's move pass that, so 2nd, I dropped the view and created a table with a primary key. Deleted the view from the model. I added the new table to the model with "Update model from db", it now includes the new table, saved and rebuilt. When I try to add a View to my solution, it reports "Entity Type table1 has no key defined. Define the key for this entity type." The table is not an entity type, not sure why VS is thinking it is, it's a table. I've cleaned and rebuilt the solution. Just adding 1 table with 2 columns, the 1st column is the primary key. How hard should this be? Microsoft manages to complicate simplest things. Models are due to change in every development environment, VS should account for changes to incorporate. And most importantly views in a database do not have primary keys-- should not be required and flagged as an error in the model. I've been at this issue for hours now, can't get around it to generate a simple View in the solution.

Continue reading...
 
Back
Top