Warning error 6002: primary key not specified in table / view

This section is here several times, but there is no answer, give me an option on how to avoid this problem in EF.

My warning:

Warning Error 6002: Table / View 'ADContainersWithEnvironmentsView' does not have a primary key. This key was inferred, and the definition was created as a table / read-only view.

I mainly use the first database approach with EF in my project.

I have a view:

CREATE VIEW [dbo].ADContainersWithEnvironmentsView AS WITH ADContainerWithEnvironments(Id, LinkedEnvironmentId) AS ( SELECT adc.Id, adc.LinkedEnvironmentId FROM ADContainer AS adc WHERE ParentAdContainerId IS NULL UNION ALL SELECT subAdc.Id, parentAdc.LinkedEnvironmentId FROM ADContainer AS subAdc INNER JOIN ADContainerWithEnvironments parentAdc ON subAdc.ParentAdContainerId = parentAdc.ID ) SELECT ISNULL(Id,-1) AS Id, LinkedEnvironmentId FROM ADContainerWithEnvironments 

As explained in other topics, I need to specify PK in my view using ISNULL (Id, -1) AS Id

I also mark my Identifier as an Entity Key in the Chart to check my screenshot enter image description here

I have this warning for all my 10 views. After my changes, I will close my visual studio, even restart the computer or try on another computer :), but there is still a warning.

Thanks for the help.

+5
source share
1 answer

You get a warning because the view does not have a Primary Key in the same sense as tables. Since you probably won’t insert anything into the view, you can ignore the warning and use the view only for queries.

-1
source

Source: https://habr.com/ru/post/1234998/


All Articles