Entity framework EF ComplexType列名(ModelFirst)
我正在做一个EF6项目(ModelFirst) 我在所有表中都使用名为“UserInfo”的复杂类型 但是,当我从模型创建数据库时,列的前缀是复杂类型的名称(例如:UserInfo_CreationDate) 是否有方法在模型中定义不带前缀的列名(CreationData代替UserInfo_CreationDate)?您可以使用或 对于Entity framework EF ComplexType列名(ModelFirst),entity-framework,complextype,ef-model-first,Entity Framework,Complextype,Ef Model First,我正在做一个EF6项目(ModelFirst) 我在所有表中都使用名为“UserInfo”的复杂类型 但是,当我从模型创建数据库时,列的前缀是复杂类型的名称(例如:UserInfo_CreationDate) 是否有方法在模型中定义不带前缀的列名(CreationData代替UserInfo_CreationDate)?您可以使用或 对于FluentApi,重写dbContext类中的OnModelCreating方法 并且,对于类UserInfo的每个属性,添加一个HasColumnName定
FluentApi
,重写dbContext
类中的OnModelCreating
方法
并且,对于类UserInfo
的每个属性,添加一个HasColumnName
定义,如下所示:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<YourEntity>().Property(s => s.UserInfo.CreationDate).HasColumnName("CreationData");
}
public class UserInfo
{
.....
[Column("CreationDate")]
public DateTime CreationDate {get; set;}
.....
}