当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net mvc 3 - MVC3: Set default values within "Code-Only"

问题描述:

How to set default values for my "Code-Only" class (pass to sdf or mdf)? Does MVC3 release support this feature?

网友答案:

You should be able to set the default values via the class constructor. For example - I have the following data model class. I am using MVC3 and 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; }
    }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: