EF4.0 给字段设置默认值
public class ModelA{ public int? _id; public int? Id { get { if (_id == null) { return 0; //默认值 } else { return _id; } } set { _id = value; } }}
以上是园里WLF教我的.
另外我还找到一个老外版
http://stackoverflow.com/questions/6237619/ef-4-1-how-to-add-a-default-on-insertion-for-datetime-column
仅在EF 4.1 Code First内测试过~
good!