8

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.

crthompson
  • 15,653
  • 6
  • 58
  • 80
user2001457
  • 165
  • 1
  • 1
  • 8

1 Answers1

15

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.

Ajay2707
  • 5,690
  • 6
  • 40
  • 58
HOKBONG
  • 795
  • 7
  • 17
  • Unfortunately that is not what seems to be the problem. I have a primary key on the table. I am working on the internal of entity framework integration with a custom ADO.NET driver for a java based database. When EF code query the database using the required API, it gets back metadata that clearly shows the PRIMARY key is present in the table but when generating the model XML, it is giving me the issue. I am looking for a internal solution that could be missing. Anyone out there in the Microsoft EF group or MySQL group may have handled this kind of issues. Thanks for looking into it. – user2001457 Feb 21 '14 at 17:36
  • I have run into exactly this same issue. We have MS SQL Server with linked Oracle database and views on the oracle tables. When generating entities from the views I get this problem and it won't generate the classes. I manually set all the keys, but it still won't generate. – Pete Apr 03 '14 at 18:07
  • I was given answer in https://stackoverflow.com/questions/2189515/tables-dont-show-when-re-adding-them-to-entity-model-edmx/31358295#31358295 link as its highest rating. – Ajay2707 Nov 08 '17 at 12:43