テーブルがInvoice
あり、列が 1 つありますAssetId
。それは他の 2 つのテーブルに関連してInsurer
いCustomer
ますが、この列 ( AssetId
) では、メイン テーブル列が関連しているテーブル値の 1 つを見つける必要があります。
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
});