View has no primary key?

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Mojo
Posts: 4
Joined: Thu 12 Dec 2019 11:44

View has no primary key?

Post by Mojo » Mon 14 Sep 2020 19:29

As I understand EF, all views must have a primary key. Though it's not possible in SQL Server View to set a primary key, so one have to do it manually in DevArt EF model. But if I recreate the model, all manual primary keys in views are lost.

I don't get it.

How do I preserve all the keys I have set manual in the views when recreating the model?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: View has no primary key?

Post by Shalex » Tue 15 Sep 2020 14:35

Update From Database Wizard remembers the choice made once in the wizard. For example, you unchecked the change for particular classes, and after this, the corresponding change will be unchecked by default in the next runs of Update From Database Wizard.

Mojo
Posts: 4
Joined: Thu 12 Dec 2019 11:44

Re: View has no primary key?

Post by Mojo » Fri 27 Nov 2020 08:15

I am still struggling with this :(

The "Update From Database Wizard" does not remember the primary key I have set.

If I create a new DevArt EF class using database first, then all my views are "red" and the want me to specify a primary key. So I double click the view and specify the key.

If I in Sql server updates a view and then use "Update From Database Wizard" then the primary key is gone and the view is "Red" again. If I "Recreate model" then ALL my primary view keys are gone.

So I need to ask again ... How do I preserve all the keys I have set manual in the views when recreating the model?

Thanks.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: View has no primary key?

Post by Shalex » Mon 30 Nov 2020 16:33

Mojo wrote: Fri 27 Nov 2020 08:15 If I in Sql server updates a view and then use "Update From Database Wizard" then the primary key is gone and the view is "Red" again.
Please specify EntityKey=True for view's property in SSDL (*.Store) part of your model, run Update From Database Wizard. The wizard will detect the change and mark the corresponding column with a checkbox - clear selection of this checkbox once. Then, after you add more columns to your view in SQL Server, run Update From Database Wizard again - the new columns will be detected and their checkboxes will be selected, the change of the "EntityKey" column will be detected again but its checkbox should be still unselected (because you cleared its selection on one of the previous wizard runs).
Mojo wrote: Fri 27 Nov 2020 08:15If I "Recreate model" then ALL my primary view keys are gone.
Do not select "Recreate model", because it creates a new model.

AlexBrown
Posts: 6
Joined: Wed 06 Jun 2018 11:02
Contact:

Re: View has no primary key?

Post by AlexBrown » Wed 16 Dec 2020 14:38

I've also been struggling with this issue

Post Reply