我一直在使用实体框架CTP4研究代码优先,您可以使用ModelBuilder来构建您的表列。有没有办法使用ModelBuilder或其他机制为数据库中的列设置默认值?
谢谢!
发布于 2010-10-28 04:43:35
除了通过文本编辑器/应用程序手动编辑之外,找不到添加默认值的方法这是实体框架中的错误...
发布于 2011-02-18 01:47:34
我使用构造函数来设置默认值。从未让我失望过
public class Activity
{
[Required]
public DateTime AddedDate { get; set; }
public Activity()
{
AddedDate = DateTime.Now;
}
}发布于 2013-05-03 22:03:32
在为迁移生成的代码中,您可以为列指定默认值:
AddColumn("users", "ReceiveSummaryEmail", c => c.Boolean(nullable: false, defaultValue: true));https://stackoverflow.com/questions/4036705
复制相似问题