[英]Entity framework 6.1.3 set default value
I have the following class. 我有以下课程。
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; }
}
How can I set default value for property IsDeleted
using Fluent API. 如何使用Fluent API设置属性IsDeleted
默认值。 Method HasDefaultValue
is not available. 方法HasDefaultValue
不可用。 I have tried to set via constructor, the same result. 我试图通过构造函数设置相同的结果。
If you are using C#6 +, it has added the ability to assign a default value to auto-properties . 如果您使用的是C#6 +,则添加了为auto-properties分配默认值的功能 。 So you can simply write something like this: 因此,您可以简单地编写如下内容:
public bool IsDeleted { get; set; } = false;
This will set the default value to false when this column is added to your database. 当此列添加到数据库时,这会将默认值设置为false。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.