【发布时间】:2020-05-23 16:31:42
【问题描述】:
我有以下型号:
public class Item {
public string ItemID {get; set;}
public decimal AvailableQuantity {get; set;}
}
public class Element {
public string ElementID {get; set;}
[ForeignKey("Item")]
public string ItemID { get; set; }
public virtual Item Item { get; set; }
public decimal Quantity {get; set;}
}
我希望 Element 中的 Quantity 字段始终小于它所代表的 Item。我尝试使用万无一失的数据注释:
[Foolproof.LessThanOrEqualTo(Item.AvailableQuantity)]
public decimal Quantity { get; set; }
但我收到以下错误:
CS0120: An object reference is required for the non-static field, method, or property 'Element.Item'
我能做些什么来满足这个条件?我想用它来验证表单中的数据。
【问题讨论】:
标签: asp.net-mvc entity-framework model