110,535
社区成员
发帖
与我相关
我的任务
分享
public class BaseModel
{
/// <summary>
/// 行状态
/// </summary>
[Display(Name = "行状态", AutoGenerateField = false)]
public TrackingState TrackingState { get; set; }
/// <summary>
/// 构造方法
/// </summary>
protected BaseModel()
{
//设置修改跟踪默认状态
TrackingState = Core.TrackingState.NoChange;
//获得属性,根据DefaultValueAttribute设置默认值
Type modelType = this.GetType();
PropertyInfo[] properties = modelType.GetProperties();
foreach (var property in properties)
{
//取得DefaultValueAttribute
object[] attributes = property.GetCustomAttributes(typeof(DefaultValueAttribute), false);
if (attributes != null && attributes.Count() > 0)
{
var attrib = (DefaultValueAttribute)attributes[0];
this.SetPropertyValue(property.Name, attrib.Value);
}
}
}
public partial class ass_ba_itemVm : BaseModel
{
///<summary>
///资产Id
///</summary>
[Key, Required]
[Display(Name = "资产Id")]
public long ItemId { get; set; }
///<summary>
///状态{1 有效 / 0 无效}
///</summary>
[Required, StringLength(20)]
[Display(Name = "状态")]
[DefaultValue("1")] //此默认值1111111111111111111111111
public string Status { get; set; }
}