Page 1 of 1

View has no primary key?

Posted: Mon 14 Sep 2020 19:29
by Mojo
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?

Re: View has no primary key?

Posted: Tue 15 Sep 2020 14:35
by Shalex
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.

Re: View has no primary key?

Posted: Fri 27 Nov 2020 08:15
by Mojo
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.

Re: View has no primary key?

Posted: Mon 30 Nov 2020 16:33
by Shalex
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.

Re: View has no primary key?

Posted: Wed 16 Dec 2020 14:38
by AlexBrown
I've also been struggling with this issue