我用“ADO.NET Entity Data Model”创建我的模型类,所以如果我改变我的数据库,我的模型类就会改变..
我的第一堂课来自“ADO.NET 实体数据模型”;
public partial class TableA
{
public TableA()
{
this.TableBs = new HashSet<TableB>();
}
public int TableAID { get; set; }
public string TableAName { get; set; }
public virtual ICollection<TableB> TableBs { get; set; }
}
我的第二堂课来自“ADO.NET Entity Data Model”;
public partial class TableB
{
public TableB()
{
this.TableAs = new HashSet<TableA>();
}
public int TableBID { get; set; }
public string TableBName { get; set; }
public int TableCID { get; set; }
public virtual TableC TableC { get; set; }
public virtual ICollection<TableA> TableAs { get; set; }
}
我的第三堂课来自“ADO.NET Entity Data Model”;
public partial class TableC
{
public TableC()
{
this.TableBs = new HashSet<TableB>();
}
public int TableCID { get; set; }
public string TableCName { get; set; }
public virtual ICollection<TableB> TableBs { get; set; }
}
还有我的 ViewModel;
public class MyViewModel
{
public TableA tableA { get; set; }
public IEnumerable<TableB> tableBs { get; set; }
public IEnumerable<TableC> tableCs { get; set; }
}
我想在我的 ViewModel 中这样做;
[Required]
[Display(Name = "TableA Name")]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
public string TableAName { get; set; }
我怎样才能做到这一点??