【发布时间】:2013-12-22 09:17:44
【问题描述】:
我在使用数据库优先方法模型验证时遇到问题,我阅读了 Scott Gu 的著名 ASP.NET MVC 2: Model Validation,但问题是它在我的 mvc 项目中不起作用,我在 Project.Model 类中有我的 Edmx 文件库,以及我在 Project.Model.Membership 命名空间中的验证类,我在这里并没有真正理解问题的概念。 这是代码:
namespace Project.Model
//part of generated code by EF database first
public partial class Member
{
public Member()
{
this.SideDuties = new HashSet<SideDuty>();
this.Member_In_Role = new HashSet<Member_In_Role>();
this.Messages = new HashSet<Message>();
this.Messages1 = new HashSet<Message>();
}
public System.Guid mId { get; set; }
public byte MemberTypeNo { get; set; }
public string mName { get; set; }
public string mLName { get; set; }
public string mUserName { get; set; }
public string mPass { get; set; }
public Nullable<byte> MarriageStatusNo { get; set; }
public Nullable<byte> GenderNo { get; set; }
public Nullable<int> mPhone { get; set; }
public Nullable<long> mMobile { get; set; }
public Nullable<int> mEmrgPhone { get; set; }
public Nullable<long> mEmrgMobile { get; set; }
public string mEmail { get; set; }
public string mProfilePicExt { get; set; }
public bool mIsOperator { get; set; }
public bool mIsAdmin { get; set; }
public virtual ...
}
namespace Project.Model.membership
//my class handling data annotations, not work!
[MetadataType(typeof(Member_Validation))]
public partial class Member
{
}
//buddy class
[Bind(Exclude = "mId")]
public sealed class Member_Validation
{
//public System.Guid mId { get; set; }
public byte MemberTypeNo { get; set; }
[Required(ErrorMessage = "blah blah")]
public string mName { get; set; }
[Required]
public string mLName { get; set; }
public string mUserName { get; set; }
public string mPass { get; set; }
public Nullable<byte> MarriageStatusNo { get; set; }
public Nullable<byte> GenderNo { get; set; }
public Nullable<int> mPhone { get; set; }
public Nullable<long> mMobile { get; set; }
public Nullable<int> mEmrgPhone { get; set; }
public Nullable<long> mEmrgMobile { get; set; }
public string mEmail { get; set; }
public string mProfilePicExt { get; set; }
public bool mIsOperator { get; set; }
public bool mIsAdmin { get; set; }
}
【问题讨论】:
标签: asp.net-mvc entity-framework asp.net-mvc-4 data-annotations model-validation