1

我有一张桌子Invoice,它有一列AssetId;并且它与另外两个表相关InsurerCustomer但是对于此列 ( AssetId),我需要找到与主表列相关的表值之一。

我写了一个 Linq 查询,当可用的记录太多时,它似乎很复杂。

注意:AssetId不是外键。

我的查询是:

var query = (from c in _invoiceRepository.Table
                     join d in _CustomerRepository.Table
                     on c.AssetID equals d.CustomerID
                     where c.CompanyID == companyID && (c.Deleted == false || c.Deleted == null)
                     select new
                     {
                         InvoiceID = c.InvoiceID,
                         ApplyTo = c.ApplyTo,
                         CustomerID = c.AssetID,
                         ContactID = c.ContactID,
                         Name = d.FullName,
                         InvoiceNo = c.InvoiceNo,
                         InvoiceDate = c.InvoiceDate,
                         TotalExGST = c.TotalExGST,
                         GST = c.GST,
                         TotalIncGST = c.TotalIncGST,
                         QuickInvoiceDesc = c.QuickInvoiceDesc,
                         companyID = c.CompanyID,
                         CreatedDate = c.CreatedDate
                     }).Union
                     (from c in _invoiceRepository.Table
                      join d in _insurerRepository.Table
                      on c.AssetID equals d.InsurerID
                      where c.CompanyID == companyID && (c.Deleted == false || c.Deleted == null)
                      select new
                      {
                          InvoiceID = c.InvoiceID,
                          ApplyTo = c.ApplyTo,
                          CustomerID = c.AssetID,
                          ContactID = c.ContactID,
                          Name = d.Name,
                          InvoiceNo = c.InvoiceNo,
                          InvoiceDate = c.InvoiceDate,
                          TotalExGST = c.TotalExGST,
                          GST = c.GST,
                          TotalIncGST = c.TotalIncGST,
                          QuickInvoiceDesc = c.QuickInvoiceDesc,
                          companyID = c.CompanyID,
                          CreatedDate = c.CreatedDate
                      });
4

0 回答 0