簡體   English   中英

將復合poco映射到EF objectcontext實體

[英]Mapping composite poco to EF objectcontext entities

我必須從3個單獨的表(每個表有幾個字段)產生一個輸出到1個輸出。 我有一個代表該輸出的類。 數據從EF 6.1.x的linq查詢中拉出ObjectContext(由於我的客戶需求的性質而被困在使用ObjectContext的情況下...)實體(在查詢中正確連接的3個類)到新類的列表中(列表<>)。 我填充一個網格,一切都很好。 但是,用戶想要編輯網格中的數據,現在我需要將這些新更改推回去。

我的問題是:我可以將新類映射回實體域嗎? 還是我堅持遍歷集合並分別更新表? 我以為我可以作圖,但是我沒有遇到任何可以證實這一點的東西。

您不能使用“代理”模式來執行此操作嗎?

我在下面做了一個2實體+包裝器示例的偽示例。

EF將“保存” SuperWrapper.DeptProxy和SuperWrapper.EmpProxy。

public partial class DepartmentEFEntity    {
    public virtual Guid? DepartmentUUID { get; set; }

    public virtual string DepartmentName { get; set; }
    public virtual ICollection<EmployeeEFEntity> Employees { get; set; }

}



public partial class EmployeeEFEntity
{

    public virtual Guid? ParentDepartmentUUID { get; set; }

    public virtual Guid? EmployeeUUID { get; set; }

    public virtual DepartmentEFEntity ParentDepartment { get; set; }

    public virtual string SSN { get; set; }
}



public class SuperWrapper
{

    internal DepartmentEFEntity DeptProxy { get; private set; }
    internal EmployeeEFEntity EmpProxy { get; private set; }

    public SuperWrapper(DepartmentEFEntity dept, EmployeeEFEntity emp)
    {
        this.DeptProxy = dept;
        this.EmpProxy = emp;
    }

    public string DepartmentName
    {
        get { return null == this.DeptProxy ? string.Empty : this.DeptProxy.DepartmentName; }
        set { if(null!=this.DeptProxy{this.DeptProxy.DepartmentName =value;}}
    }

    public string EmployeeSSN
    {
        get { return null == this.EmpProxy ? string.Empty : this.EmpProxy.SSN; }
        set { if(null!=this.EmpProxy{this.EmpProxy.SSN =value;}}
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM