【发布时间】:2015-09-05 20:23:06
【问题描述】:
我有一个基类,它具有类似的审计属性
public abstract class BaseModel
{
[Column(Order = 1)]
public long Id { get; set; }
public long CreatedBy { get; set; }
public DateTime CreatedDate { get; set; }
public long ModifiedBy { get; set; }
public DateTime ModifiedDate { get; set; }
public bool IsActive { get; set; }
}
我所有的 poco 类都派生自这个类。
我正在尝试为 IsActive 属性设置默认值。我不热衷于使用注释,因此我是否可以使用流利的 API 来处理这个问题。
我试过了,但它不起作用。似乎它创建了一个名为 BaseModel 的新表
modelBuilder.Entity<BaseModel>()
.Property(p => p.IsActive)
.HasColumnAnnotation("DefaultValue", true);
任何人都可以在这里提出一种方法吗?
【问题讨论】:
标签: entity-framework entity-framework-6 ef-fluent-api