为什么实体框架数据注释没有被提取

时间:2017-09-19 01:15:00

标签: c# entity-framework

我有以下解决方案结构:

(项目)AppNameSpace.Model

  • ModelValidation.cs
  • WebModel.edmx

内部ModelValidation.cs我有

[MetadataType(typeof(CMPlan.MetaData))]
public partial class CMPlan
{
    internal class MetaData
    {
        [Range(100.0, double.MaxValue, ErrorMessage = "Invalid number of people.")]
        public double peopleCount { get; set; }
    }
}

我试图保存peopleCount小于100,但它通过了。问题是如何指导它进行验证?

修改

以下语法也无济于事:

[MetadataType(typeof(CMPlanMetaData))]
public partial class CMPlan
{
    public int newProperty {get;set;} // This, however, shows up like expected
}

public class CMPlanMetaData
{
    [Range(100.0, double.MaxValue, ErrorMessage = "Invalid number of people.")]
    public double peopleCount { get; set; }
}

0 个答案:

没有答案