【发布时间】:2015-01-23 23:12:42
【问题描述】:
我正在尝试为我的一个实体创建自定义验证方法,因此我创建了一个继承自 ValidationAttribute 的类:
public class OneWheelchairPerTrainAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
// This is where I need to access the other entity property
}
}
我正在努力解决的是如何访问实体上的其他属性。这是我的实体:
public class Ticket
{
public int Id { get; set; }
[Required]
public int TimetableId { get; set; }
[Required]
public bool Wheelchair { get; set; }
public virtual Timetable Timetable { get; set; }
}
我正在编写的验证注释将应用于Wheelchair 属性,我需要从我的验证方法中访问TimetableId 属性。
【问题讨论】:
标签: c# asp.net-mvc entity-framework validation