[MetadataType(typeof(MemberMetadata))]
public partial class Member
{
private class MemberMetadata
{
public int ID { get; set; }
[Required(ErrorMessage = "请输入帐号")]
[StringLength(50, ErrorMessage = "请勿输入超过50个字")]
[DisplayName("账号")]
public string Account { get; set; }
[Required(ErrorMessage = "请输入密码")]
[StringLength(50, ErrorMessage = "请勿输入超过50个字")]
[DisplayName("密码")]
public string password { get; set; }
public DateTime CreateTime { get; set; }
}
partial void OnCreated()
{
this.CreateTime = DateTime.Now;//为什么找不到this.CreateTime
}
}
------解决方案--------------------
你定义在inner class中了。
------解决方案--------------------
this 代表你当前所处的这个对象 即 Member 这个类,当然找不到,你把OnCreated()放到MemberMetadata这个类里面就行
------解决方案--------------------
[MetadataType(typeof(MemberMetadata))]
public partial class Member
{
private class MemberMetadata
{
public int ID { get; set; }
[Required(ErrorMessage = "请输入帐号")]
[StringLength(50, ErrorMessage = "请勿输入超过50个字")]
[DisplayName("账号")]
public string Account { get; set; }
[Required(ErrorMessage = "请输入密码")]
[StringLength(50, ErrorMessage = "请勿输入超过50个字")]
[DisplayName("密码")]
public string password { get; set; }
}
public DateTime CreateTime { get; set; } ///挪出来
partial void OnCreated()
{
this.CreateTime = DateTime.Now;//为什么找不到this.CreateTime
}
}