我有以下课程。
public class User
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public byte[] RowVersion { get; set; }
public bool IsDeleted { get; set; }
}
如何使用Fluent API为属性IsDeleted
设置默认值。方法HasDefaultValue
不可用。我试图通过构造函数设置相同的结果。
答案 0 :(得分:2)
如果您使用的是C#6 +,则会添加the ability to assign a default value to auto-properties。所以你可以简单地写下这样的东西:
public bool IsDeleted { get; set; } = false;
将此列添加到数据库时,这会将默认值设置为false。