我想在 DBContext 中的项目中添加 SQL 时态表,而不是在迁移文件中?如何实现?编辑:我已将它添加到种子功能,但它仍然无法正常工作
protected override void Seed(MSDBContext context)
{
string sql = @" ALTER TABLE dbo.Workshops
ADD SysStartTime datetime2 GENERATED ALWAYS AS ROW START
CONSTRAINT DF_Workshops_SysStartTime DEFAULT SYSUTCDATETIME() NOT NULL,
SysEndTime datetime2 GENERATED ALWAYS AS ROW END
CONSTRAINT DF_Workshops_SysEndTime DEFAULT CONVERT (DATETIME2, '9999-12-31 23:59:59') NOT NULL,
PERIOD FOR SYSTEM_TIME (SysStartTime, SysEndTime)
GO
ALTER TABLE dbo.Workshops
SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.WorkshopsHistory))
GO";
context.Database.ExecuteSqlCommand(sql);
context.SaveChanges();
context.Configuration.LazyLoadingEnabled = false;
}