"A dependent property in a ReferentialConstraint is mapped to a store-generated column." on a persisted computed column (EntityFramework DB first) "A dependent property in a ReferentialConstraint is mapped to a store-generated column." on a persisted computed column (EntityFramework DB first) asp.net asp.net

"A dependent property in a ReferentialConstraint is mapped to a store-generated column." on a persisted computed column (EntityFramework DB first)


I know nothing about EF, but I'd create your TYPE columns as normal columns, not calculated, not persisted.

Then I'd set their default value to the required value and add a CHECK constraint to make sure that it can't be changed.

The rest of your T-SQL script where your set up foreign keys remains the same.

For example, for NATURAL_USER it would look like this:

CREATE TABLE [dbo].[NATURAL_USER](    [ID] [int] NOT NULL,    [TYPE] [int] NOT NULL,    [BirthDate] [date] NOT NULL,CONSTRAINT [PK_NATURAL_USER] PRIMARY KEY CLUSTERED (    [ID] ASC))GOALTER TABLE [dbo].[NATURAL_USER]  WITH CHECK ADD  CONSTRAINT [CK_NATURAL_USER] CHECK  (([TYPE]=(1)))GOALTER TABLE [dbo].[NATURAL_USER] CHECK CONSTRAINT [CK_NATURAL_USER]GOALTER TABLE [dbo].[NATURAL_USER] ADD  CONSTRAINT [DF_NATURAL_USER_TYPE]  DEFAULT ((1)) FOR [TYPE]GO


I have made a terrible mistake when implementing the approach, but it worked before. I messed up the constraint FK_NATURAL_USER___USER___TYPEVALIDATION, accidentally.

It should have been build like the FK_JURIDICAL_USER___USER___TYPEVALIDATION constraint.

The EF is able to handle the persisted columns. The problem was it tried to write to the PK of [USER_T] that should not be apart of the constraint at all.

I'm sorry for all people who wasted time on this.