Entity framework EF ComplexType列名(ModelFirst)

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定

我正在做一个EF6项目(ModelFirst)

我在所有表中都使用名为“UserInfo”的复杂类型

但是,当我从模型创建数据库时,列的前缀是复杂类型的名称(例如:UserInfo_CreationDate)

是否有方法在模型中定义不带前缀的列名(CreationData代替UserInfo_CreationDate)?

您可以使用或

对于
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;}

    .....
}