我正在做一个EF6项目(ModelFirst)。
我在所有的表中都使用了名为"UserInfo“的复杂类型。
但是,当我从模型创建数据库时,列的前缀是复杂类型的名称(例如: UserInfo_CreationDate)
有没有办法在模型中定义不带前缀的列名(用CreationData代替UserInfo_CreationDate)?
发布于 2014-03-12 19:45:08
您可以使用或。
对于FluentApi,覆盖dbContext类中的OnModelCreating方法,并为UserInfo类的每个属性添加如下所示的HasColumnName定义:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<YourEntity>().Property(s => s.UserInfo.CreationDate).HasColumnName("CreationData");
}对于Annotations,在类UserInfo的每个属性中添加如下注释:
public class UserInfo
{
.....
[Column("CreationDate")]
public DateTime CreationDate {get; set;}
.....
} https://stackoverflow.com/questions/22349868
复制相似问题