我可以让 EF 代码优先 TPH 具有非抽象基础 class 吗?
Can I have EF code first TPH with a non abstract base class?
在 SQL 服务器中有一个 table 由
定义
CREATE TABLE [dbo].[ReportDataV2](
[ID] [int] IDENTITY(1,1) NOT NULL,
[DataTypeName] [nvarchar](max) NULL,
[IsInplaceReport] [bit] NOT NULL,
[PredefinedReportTypeName] [nvarchar](max) NULL,
[Content] [varbinary](max) NULL,
[DisplayName] [nvarchar](max) NULL,
[ParametersObjectTypeName] [nvarchar](max) NULL,
CONSTRAINT [PK_dbo.ReportDataV2] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
恰好是 Dev Express XAF 报告 table。
在我的数据上下文中,我有
public DbSet<ReportDataV2> ReportDataV2 { get; set; }
我希望能够将 DataTypeName 字段视为鉴别器列,而不会干扰 ReportDataV2 在我的代码中已经工作的方式。
我尝试了以下操作,但 Entity Framework 检测到数据结构已更改,如果我生成迁移,我会看到它正在尝试重新创建 ReportDataV2 table.
public class OrderCountReport2Configuration : EntityTypeConfiguration<ReportDataV2>
{
public OrderCountReportConfiguration()
: base()
{
ToTable("ReportDataV2", "dbo");
HasKey(tp => tp.ID);
Map<OrderCountReport>(m => m.Requires("DataTypeName").HasValue("OrderCountReport"));
}
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new OrderCountReportConfiguration());
base.OnModelCreating(modelBuilder);
}
}
鉴别器列必须有大小限制,就像索引列需要大小限制一样
在 SQL 服务器中有一个 table 由
定义 CREATE TABLE [dbo].[ReportDataV2](
[ID] [int] IDENTITY(1,1) NOT NULL,
[DataTypeName] [nvarchar](max) NULL,
[IsInplaceReport] [bit] NOT NULL,
[PredefinedReportTypeName] [nvarchar](max) NULL,
[Content] [varbinary](max) NULL,
[DisplayName] [nvarchar](max) NULL,
[ParametersObjectTypeName] [nvarchar](max) NULL,
CONSTRAINT [PK_dbo.ReportDataV2] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
恰好是 Dev Express XAF 报告 table。
在我的数据上下文中,我有
public DbSet<ReportDataV2> ReportDataV2 { get; set; }
我希望能够将 DataTypeName 字段视为鉴别器列,而不会干扰 ReportDataV2 在我的代码中已经工作的方式。
我尝试了以下操作,但 Entity Framework 检测到数据结构已更改,如果我生成迁移,我会看到它正在尝试重新创建 ReportDataV2 table.
public class OrderCountReport2Configuration : EntityTypeConfiguration<ReportDataV2>
{
public OrderCountReportConfiguration()
: base()
{
ToTable("ReportDataV2", "dbo");
HasKey(tp => tp.ID);
Map<OrderCountReport>(m => m.Requires("DataTypeName").HasValue("OrderCountReport"));
}
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new OrderCountReportConfiguration());
base.OnModelCreating(modelBuilder);
}
}
鉴别器列必须有大小限制,就像索引列需要大小限制一样