C# 实体框架代码优先映射情况
我尝试先使用EF4.3代码将现有应用程序(使用纯ADO.Net)移植到新应用程序。值得一提的是,这是我第一次使用EF 基本上我有一个suppliers表,但有两个specialization表,其属性特定于这两种类型的供应商 以下是现有数据库的外观:C# 实体框架代码优先映射情况,c#,entity-framework,ef-code-first,C#,Entity Framework,Ef Code First,我尝试先使用EF4.3代码将现有应用程序(使用纯ADO.Net)移植到新应用程序。值得一提的是,这是我第一次使用EF 基本上我有一个suppliers表,但有两个specialization表,其属性特定于这两种类型的供应商 以下是现有数据库的外观: create table Supplier( id_supplier int not null identity --Bunch of other attributes ); create table Individual( id_individ
create table Supplier(
id_supplier int not null identity
--Bunch of other attributes
);
create table Individual(
id_individual int not null --not identity, gets the same value as the Supplier table
--Attributes specific to individuals
);
alter table Individual add constraint fk_individual_supplier
foreign key(id_individual) references Supplier(id_supplier);
create table Corporation(
id_corporation int not null --not identity, gets the same value as the Supplier table
--Attributes specific to corporations
);
alter table Corporation add constraint fk_corporation_supplier
foreign key(id_corporation) references Supplier(id_supplier);
因此,如表所示,供应商可以是个人也可以是公司
现有应用程序如下所示:
- 抽象类及其属性
- 使用附加属性对从供应商派生的个人进行分类
- 从供应商及其附加属性派生的类别公司
提前感谢您的帮助。这听起来像是“每种类型的表”继承(TPT)。对于TPT,有一个基表,其中列对于所有派生类型都是通用的,每个派生类型的表都有特定于类型的列。实体框架支持这个模型。有关如何使用数据注释和流畅映射的示例,请参阅优秀的博客文章。这是我100%的情况。谢谢!