将两个类合并为1作为匿名类?

时间:2013-12-10 05:32:24

标签: c# entity-framework linq-to-entities

它看起来像EF不允许这样做,如何实际使其工作,因为我不想将变量从2类复制到1,我尝试通过这种方式访问​​每个类中的变量,是否可能创造这样的东西?

匿名类

public class PurchaseOrderHeaderDTO
{
    public PurchaseOrderHeaderDTO()
    {
    }

    public virtual PurchaseOrderHeader PurchaseOrderHeader { get; set; }

    public virtual Supplier Supplier { get; set; }
}

实体框架

var result = PurchaseOrderHeaders
                 .Join(qbmWBSContext.Suppliers,
                    c => c.SupplierCode,
                    d => d.SupplierCode,
                    (d, c) => new { d, c })
                 .Where(dc => dc.c.CompanyCode == sCompany &&
                     dc.c.RegionalCode == sRegional &&
                     dc.c.SiteCode == sSiteCode &&
                     dc.c.Status == "1")
                 .Select(dc => new PurchaseOrderHeaderDTO
                     {
                         PurchaseOrderHeader = new PurchaseOrderHeader
                         {
                             RecordID = dc.d.RecordID,
                             OrderNumber = dc.d.OrderNumber,
                             SupplierCode = dc.c.SupplierCode
                         },
                         Supplier = new Supplier
                         {
                             SupplierName = dc.c.SupplierName
                         }
                     });

更新

我设法找到了一种方式

PurchaseOrderDTO

public class PurchaseOrderDTO
    {
        public PurchaseOrderHeaderDTO PurchaseOrderHeader { get; set; }
        public PurchaseOrderLineDTO PurchaseOrderLine { get; set; }
        public SupplierDTO Supplier { get; set; }


    }

    public class PurchaseOrderHeaderDTO:PurchaseOrderHeader
    {
    }

    public class PurchaseOrderLineDTO:PurchaseOrderLine
    {
        //public decimal BalanceQuantity { get; set; }

    }

    public class SupplierDTO : Supplier
    {

    }

0 个答案:

没有答案