0

I ensured my tables all have primary keys which are not null fields. I ensured my views contain one of these primary key fields. Nothing works.

When I try to add the views in the wizard, Visual Studio returns me to the EDMX diagram view but the views I just added are not there! This below shows when returned to the diagram view:

The model was generated with warnings or errors.PMCPolyModel.edmx 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:00.5619194. Generating the model took 00:00:00.5230463. Added the connection string to the App.Config file."

The internal error is:

Error 6013: The table/view '[My View Name]' 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."

I closed and reopened Visual Studio and the EDMX diagram view states "The Entity Data Model Designer is unable to display the file you requested. You can edit the model using the XML Editor."

Ashley
  • 179
  • 2
  • 9
  • If you are using npgsql this has been a problem and is still [pending](https://github.com/npgsql/EntityFramework6.Npgsql/issues/37) – Juan Carlos Oropeza Oct 23 '17 at 20:51
  • I have tried so many solutions online over the last week. Nothing seems to work. Is this a know issue with no good solution? – Ashley Oct 23 '17 at 21:05
  • Yes is a know issue. Check the link. One of the developer ask the main guy if they have any solution for this just 10 days ago. – Juan Carlos Oropeza Oct 23 '17 at 21:06
  • Sorry. I did not notice the word pending was a link. I am trying a [new solution](https://stackoverflow.com/questions/7461265/how-to-use-views-in-code-first-entity-framework), but so far it is not working either – Ashley Oct 23 '17 at 21:10
  • I have yet to find a solution and am thinking it is impossible without buying a tool! :( I am tempted to download [DevArt](https://www.devart.com), but would rather not have to buy a tool to setup my database in Visual Studio. Have you use this tool? Is it worth purchasing? – Ashley Oct 25 '17 at 15:39
  • Dont know the tool. But what use are you going to give to that view? Cant you just create a DataAdapter to read the view and create a your own List<> on the model? – Juan Carlos Oropeza Oct 25 '17 at 15:42
  • I cannot add views or stored procedures. The views are easy enough to recreate... but I'm converting a site with over 160 stored procedures and views. – Ashley Oct 25 '17 at 16:03
  • mmmm not sure how is that related to my comment. Again you can read your db using DataAdapter you dont need EF for that. Of course isnt automatic as EF but can be done with some work. – Juan Carlos Oropeza Oct 25 '17 at 16:04
  • Sorry. I'm frustrated. I spent 1.5 weeks just getting the EF wizard to work with tables. Now I have to do specialty things to get the other two pieces, views and stored procedures, to work. Ugh.. but, it's the complexities that make programming exciting I guess. I will look into DataAdapter. Thank you – Ashley Oct 25 '17 at 16:22
  • More reading and I don't think using Entity Framework 6 is the best method for Npgsql. I can only get the tables to come through. If I cannot use the full benefit of EF with all objects in my database then it's not worth it for me to convert to EF. I have started on the journey of Entity Framework Core (EF7 prior to Jan 2016). So far what I've read it should work better with Npgsql. I'll report back with my results. – Ashley Oct 26 '17 at 15:14
  • I dont know your requirements, but I'm very happy with Npgsql – Juan Carlos Oropeza Oct 26 '17 at 15:15
  • I like Npgsql as well! I am not happy with EF6's attempt at implementation. I'm trying to fully separate my logic/layers in my .net application. Trying to do so in a way that if we end up moving off of Npgsql for another database, Microsoft SQL for instance, I won't have to completely re-write my web code. Probably a pipe dream but we are trying. – Ashley Oct 26 '17 at 15:18
  • But that is a different thing. You need to create an [**Interface**](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interface) and your business layer consume the interface. How you implement the interface Postgresql or Sql Server wont affect your bussiness layer – Juan Carlos Oropeza Oct 26 '17 at 15:22

0 Answers0