为什么引用的类验证属性未激活?

时间:2019-04-04 05:01:11

标签: c# class validation attributes

我有以下两个对象类:

[Serializable]
[DataContract]
public class W_ListItemPrice
{
    [DataMember]
    [Required]
    public string nSize { get; set; }
    [DataMember]
    [Required, Range(0.5, Constants.FOOD_ITEM_MAX_SELLING_PRICE, ErrorMessage = "Price range invalid")]
    public decimal ItemPrice { get; set; }
}

[Serializable]
    [DataContract]
    public class W_Listing
    {
        [DataMember]
        [Required, RegularExpression(GlobalFromat.IDformat, ErrorMessage = "Invalid FoodID format")]
        public Int64 MemberID { get; set; }
        [DataMember]
        [Required, RegularExpression(GlobalFromat.IDformat, ErrorMessage = "Invalid ScheduleID format")]
        public Int64 ScheduleID { get; set; }
        [DataMember]
        [Required]
        public List<Days?> FoodDays { get; set; }
        [Required]
        public List<W_ListItemPrice> ListingPortionPrice { get; set; }

        public W_Listing()
        {
            oDays = new List<Days?>();
            ListingPrice = new List<W_ListItemPrice>();
        }
    }

当我使用W_Listing类调用该函数时,它仅验证W_Listing类中列出的成员项。它不验证W_ListItemPrice类中的成员吗?不管我通过与否。

为什么?

0 个答案:

没有答案