Entity Framework 4.0 generating read only model when I create model from existing database

c# entity-framework sql

Question

I am working on a custom ado.net provider and using that provider I am integrating Entity Framework support in Visual Studio 2010. I'm creating all possible mapping and reading all the related metadata from database for table objects. For my test, a table contains primary keys and and other fields. When I create a model from database using this table and I get a model with all column mappings and everything but I also get error messages that follow:

The model was generated with warnings or errors. Please see the Error List for more details. These issues must be fixed before running your application. Loading metadata from the database took 00:00:11.4799371. Generating the model took 00:00:04.2751189. Added the connection string to the App.Config file. Writing the .edmx file took 00:00:00.0005060.

If I open the .edmx file with XML editor, I see the following error:

<!--Errors Found During Generation:
  warning 6002: The table/view 'sqlfire.APP.CUSTOMERS' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view.
  -->

It also added a DefiningQuery with a SELECT ... statement for the table.

I am going in a circle to find a solution and desperately looking for some help on this issue.

1
6
2/20/2014 11:12:44 PM

Popular Answer

From the error message looks like one of your table/view doesn't have a Primary-Key. EF needs a Primary-Key in every table in order to generate Entity keys.

You may still be able to run your application, but I strongly suggest you add primary keys as warned.

12
11/8/2017 12:44:42 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow