【发布时间】:2012-09-01 01:31:09
【问题描述】:
我正在尝试使用实体框架和代码优先方法为最后一个日期 (DateAdded) 属性设置默认值。这是我的代码:
namespace BackOffice.Models
{
public class UsersContext : DbContext
{
public UsersContext()
//: base("DefaultConnection")
: base("ProofPixDB")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
//public DateTime DOB { get; set; }
[DataType(DataType.Date)]
public DateTime? DOB { get; set; } //This allows null
[Required]
[DataType(DataType.Date)]
public DateTime DateAdded { get; set; }
}
}
【问题讨论】:
标签: c# entity-framework ef-code-first