Я пытаюсь запросить некоторые данные, используя EF, и я написал этот запрос EF.Говоря, что у меня есть противоречие со множественностью между KPMUnitPaypoint_KPMPaypoint_source, я просто потерялся в том, что мне нужно сделать, чтобы это исправить.Я запустил код без последнего выбора из модели, и он работает, как ожидалось.Я просто хочу установить эти элементы в этих полях, и я получаю сообщение об ошибке.
var enumerable = DataServiceLocator.GetKPMUnitPaypoints_DAO()
.GetKPMUnitPaypointsByProjectID(project_id, Context)
.Where(x => x.CompletionDate.HasValue && x.CompletionDate >= datefrom && x.CompletionDate <= dateto ||
(x.AccruedDate.HasValue && x.AccruedDate >= datefrom && x.AccruedDate <= dateto) ||
(show == "PENDING") &&
(x.KPMPaypoint.TradePhase.Trade.Proper_Trade_Name == service || service == "ALL") &&
(x.KPMPaypoint.TradePhase.Phase_Name == phase || phase == "ALL") &&
(!x.ApprovedBy.HasValue && show == "PENDING") ||
(x.Accrued.HasValue && show == "ACCRUED") ||
(x.AccruedDate.HasValue && x.Accrued.HasValue && show == "ACCRUED-APPROVED") ||
(show == "ALL" && x.Active))
.Select(x => new KPMPaypointByUnitDetailModel
{
Completed_By = Context.Employee.Where(p => p.Employee_ID == x.CompletionUser).FirstOrDefault().UserName,
Completed_Date = x.CompletionDate,
Description = x.KPMPaypoint.Description,
Vendor_Name = Context.KPMVistaVendors.Where(p => p.Vista_Vendor_ID == x.VistaVendorID).FirstOrDefault().Vista_Vendor_Name,
Amount = x.Amount,
Unit_Code = x.KPMUnit.UnitType.Code,
Unit_Type = x.KPMUnit.UnitType.Name,
Approved = x.Approved,
Approved_By = Context.Employee.Where(p => p.Employee_ID == x.ApprovedBy).FirstOrDefault().UserName,
Approved_Date = x.ApprovedDate,
Trade = x.KPMPaypoint.TradePhase.Trade.Proper_Trade_Name,
Phase = x.KPMPaypoint.TradePhase.Phase_Name,
Accrued = x.Accrued,
Accrued_Date = x.AccruedDate,
Accrued_User = Context.Employee.Where(p => p.Employee_ID == x.AccruedBy).FirstOrDefault().UserName
}).ToList().AsEnumerable();
сущность unitpaypoint:
namespace KMSEntities
{
public class KPMUnitPaypoints
{
public int UnitPaypointID { get; set; }
public int UnitID { get; set; }
public int PayPointID { get; set; }
public decimal Amount { get; set; }
public bool Billable { get; set; }
public decimal? SubPayAmount { get; set; }
public DateTime? CompletionDate { get; set; }
public int? CompletionUser { get; set; }
public int? VistaVendorID { get; set; }
public bool? Approved { get; set; }
public int? ApprovedBy { get; set; }
public DateTime? ApprovedDate { get; set; }
public bool Active { get; set; }
public bool? Accrued { get; set; }
public DateTime? AccruedDate { get; set; }
public int? AccruedBy { get; set; }
public int? ContractItem { get; set; }
[ForeignKey("PayPointID")]
public virtual KPMPaypoint KPMPaypoint { get; set; }
[ForeignKey("UnitID")]
public KPMUnits KPMUnit { get; set; }
}
}
сущность paypoint:
public class KPMPaypoint
{
public KPMPaypoint()
{
KPMUnitPaypoints = new HashSet<KPMUnitPaypoints>();
}
public int PaypointID { get; set; }
public string Code { get; set; }
[ForeignKey("TP_ID")]
public TradePhase TradePhase { get; set; }
public string Description { get; set; }
public int TP_ID { get; set; }
public ICollection<KPMUnitPaypoints> KPMUnitPaypoints { get; set; }
}
Я не уверен, как обойти эту ошибку, вот мои модели.