【发布时间】:2016-06-13 14:33:16
【问题描述】:
我有一个包含两个类的视图模型。 这些类与另一个类相关,一对多和一对一的关系。 如何将数据从视图模型传递到与其他表有关系的表中? 例如:
public class A
{
public int a_id { get; set; }
public string a_field1 { get; set; }
...
//one-to-many with B
public virtual ICollection<B> Bs { get; set; }
//one-to-one with D
public virtual D Ds { get; set; }
}
public class B
{
public int B_id { get; set; }
public string B_field1 { get; set; }
...
public int a_id { get; set; }
public int c_id { get; set; }
// one-to-many with A , C
public virtual A As { get; set; }
public virtual C Cs { get; set; }
}
public class C
{
public int C_id { get; set; }
public string C_field1 { get; set; }
...
// one-to-many with B
public virtual ICollection<B> Bs { get; set; }
// one-to-one with E
public virtual E Es { get; set; }
}
我的视图模型是由 A 和 B 组成的。 如何将信息添加到具有来自 B 的集合和来自 D 的虚拟实例的 A 中? 或者在 B 中具有来自 A 和 C 的虚拟实例? 我要更改我的视图模型吗? 请指导和建议。
【问题讨论】:
标签: asp.net-mvc entity-framework entity-framework-6