Ton*_*Bao 31 c# entity-framework ef-code-first ef-fluent-api
如何使用EntityFramework Code First FluentAPI为bool属性设置默认值?
就像是:
Property(l => l.PropertyFlag).HasColumnType("bit").DefaultValue(1);
Run Code Online (Sandbox Code Playgroud)
htx*_*yan 31
好消息,代码现在首先支持这个.在生成的迁移的"Up()"方法中,使用以下语法指定默认值:
AddColumn("[table name]", "[column name]", c => c.Boolean(nullable: false, defaultValue: false));
Run Code Online (Sandbox Code Playgroud)
我不确定流畅的方式,但你可以简单地在无参数构造函数中设置属性......
public class MyTable
{
public MyTable()
{
CanSetDefault = true;
}
public bool CanSetDefault {get; set; }
}
Run Code Online (Sandbox Code Playgroud)
更新
一个快速的谷歌建议不可能使用流畅的api ...
http://social.msdn.microsoft.com/Forums/en-US/ad854e28-02f5-451b-9000-c8bcb1355d0b/codefirst-ctp5-and-default -值?论坛= adonetefx
归档时间: |
|
查看次数: |
25870 次 |
最近记录: |