我想包含與合同相關的購買歷史串列。合同有一個歷史串列但是我只得到一個歷史我怎樣才能得到一個合同的所有歷史
var purchases = from purchase in _context.Purchases
join component in _context.Components on purchase.ComponentId equals component.ComponentId
join supplier in _context.Suppliers on component.SupplierId equals supplier.SupplierId
join contractDb in _context.Contracts on purchase.ContractId equals contractDb.ContractId into contract
from contractDb in contract.DefaultIfEmpty()
join histories in _context.Histories on purchase.ContractId equals histories.ContractId
where purchase.Step == 0
select new { component.ComponentId, purchase.SupplierId, supplier.Name, contractDb.ContractId, contractDb.ContractNumber, histories };
這是我的合同模型
public class Contract
{
[Key]
public UInt64 ContractId { get; set; }
public string ContractNumber { get; set; }
public string InitialContractNumber { get; set; }
[ForeignKey("ClienteId")]
public UInt64 ClienteId { get; set; }
[ForeignKey("ContactId")]
public UInt64? ContactId { get; set; }
[ForeignKey("ComercialEmployeeId")]
public UInt64 ComercialEmployeeId { get; set; }
[ForeignKey("TechnicalEmployeeId")]
public UInt64? TechnicalEmployeeId { get; set; }
public ulong OfferId { get; set; }
public string Brand { get; set; }
public string Type { get; set; }
public string SerialNumber { get; set; }
}
這是我的歷史模型
public class History
{
public UInt64 ContractId { get; set; }
public UInt64 StepId { get; set; }
[DataType(DataType.DateTime)]
public DateTime? InitialDate { get; set; }
[DataType(DataType.DateTime)]
public DateTime? FinalDate { get; set; }
[DataType(DataType.DateTime)]
public DateTime? Deadline { get; set; }
public string EmployeeUserName { get; set; }
public UInt64 EmployeeId { get; set; }
public virtual cfgEtapa Step { get; set; }
public virtual Contract Contract { get; set; }
}
uj5u.com熱心網友回復:
嘗試以下查詢:
var purchases =
from purchase in _context.Purchases
join component in _context.Components on purchase.ComponentId equals component.ComponentId
join supplier in _context.Suppliers on component.SupplierId equals supplier.SupplierId
join contractDb in _context.Contracts on purchase.ContractId equals contractDb.ContractId into contract
from contractDb in contract.DefaultIfEmpty()
where purchase.Step == 0
select new
{
component.ComponentId,
purchase.SupplierId,
supplier.Name,
contractDb.ContractId,
contractDb.ContractNumber,
histories = _context.Histories.Where(h => purchase.ContractId == h.ContractId).ToList()
};
如果您發布所有課程,我們可能可以洗掉連接。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/517621.html
標籤:C#林克
上一篇:如何將cmd中的引數傳遞給FileSystemWatcher?
下一篇:交織兩個向量的更好方法-SSE2
