Entity Framework not working with temporal table

后端 未结 5 1835
北海茫月
北海茫月 2020-12-03 07:37

I\'m using database first entity framework 6. After changing some of the tables in my schema to be temporal tables, I started getting the following error when attempting to

5条回答
  •  暖寄归人
    2020-12-03 08:22

    An other solution is create default constraint in the fields of the table.

    CREATE TABLE [dbo].[Table] (
        [Id]            INT IDENTITY(1, 1)  NOT NULL,
        [Description]   NVARCHAR(100)       NOT NULL,
        [ValidFrom]     DATETIME2(0)        GENERATED ALWAYS AS ROW START HIDDEN CONSTRAINT [Df_Table_ValidFrom] DEFAULT DATEADD(SECOND, -1, SYSUTCDATETIME()),
        [ValidTo]       DATETIME2(0)        GENERATED ALWAYS AS ROW END HIDDEN CONSTRAINT [Df_Table_ValidTo] DEFAULT '9999.12.31 23:59:59.99',
        PERIOD FOR SYSTEM_TIME ([ValidFrom], [ValidTo]),
        CONSTRAINT [Pk_Table] PRIMARY KEY CLUSTERED ([Id] ASC)
    ) WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [dbo].[Table_History]));
    GO
    

    In the code not need alteration nothing.

提交回复
热议问题