2016-03-01 24 views
0

我有一个包含两个类的视图模型。 这些类与另一类,一对多和一对一的关系有关。 如何将数据从viewmodel传递到与其他表格有关的表格中? 例如:在视图模型中使用的类的填充表

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 maked如何添加相关信息,分为A将距B和虚拟实例从d的集合? 或者在B中有来自A和C的虚拟实例吗? 我是否更改我的视图模型? 请指导并给我建议。

回答

0

我找到我的答案: 当你想从上面的类制作视图模型时,你不需要在视图模型中使用虚拟集合或虚拟属性。 你应该只使用你需要的属性。 在本例中,A和B您的视图模型,这将是:

public class VM_A_B 
{ 

    public int A_id { get; set; } 
    public int A_Field1 { get; set; } 
    public int b_id { get; set; } 
    public int b_Field1 { get; set; } 
    //no need any virtual collection or virtual property 
} 

好运。

+0

这是一个非常模糊的答案......如果您包含一些代码,对未来的读者会更有帮助。 –