如何为“Code-Only”类设置默认值(传递给sdf或mdf)? MVC3版本是否支持此功能?
答案 0 :(得分:2)
您应该能够通过类构造函数设置默认值。例如 - 我有以下数据模型类。我正在使用MVC3和Entity Framework 4.1。
namespace MyProj.Models
{
using System;
using System.Collections.Generic;
public partial class Task
{
public Task()
{
this.HoursEstimated = 0;
this.HoursUsed = 0;
this.Status = "To Start";
}
public int ID { get; set; }
public string Description { get; set; }
public int AssignedUserID { get; set; }
public int JobID { get; set; }
public Nullable<decimal> HoursEstimated { get; set; }
public Nullable<decimal> HoursUsed { get; set; }
public Nullable<System.DateTime> DateStart { get; set; }
public Nullable<System.DateTime> DateDue { get; set; }
public string Status { get; set; }
public virtual Job Job { get; set; }
public virtual User AssignedUser { get; set; }
}
}