我收到了多重约束违反错误

时间:2019-02-12 21:44:11

标签: c# entity-framework

我正在尝试使用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; }   
    }
}

支付点实体:

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; }
}

我不确定如何解决此错误,这是我的模型。

0 个答案:

没有答案