Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq de>(因为它是冗余的)。2) 在Where子句中使用m.FormId==id?这两个更改仍然相同您声明ApprovalModel没有外键。但是,它作为导航属性列在TechnologyProjectPlanModel,公共列表审批人{get;set;};它_Linq_Entity Framework - Fatal编程技术网

Linq de>(因为它是冗余的)。2) 在Where子句中使用m.FormId==id?这两个更改仍然相同您声明ApprovalModel没有外键。但是,它作为导航属性列在TechnologyProjectPlanModel,公共列表审批人{get;set;};它

Linq de>(因为它是冗余的)。2) 在Where子句中使用m.FormId==id?这两个更改仍然相同您声明ApprovalModel没有外键。但是,它作为导航属性列在TechnologyProjectPlanModel,公共列表审批人{get;set;};它,linq,entity-framework,Linq,Entity Framework,de>(因为它是冗余的)。2) 在Where子句中使用m.FormId==id?这两个更改仍然相同您声明ApprovalModel没有外键。但是,它作为导航属性列在TechnologyProjectPlanModel,公共列表审批人{get;set;};它肯定应该有一个FK,除非EF模型和您的SQL不一致。啊,非常感谢。我想出了另一个解决方法,但是[NotMapped]会快得多,谢谢!实体是否假设模型的任何集合都是导航属性?所有的假设都基于这里详细描述的约定类:这就是我最后要做的。我想手动执行此


de>(因为它是冗余的)。2) 在Where子句中使用
m.FormId==id
?这两个更改仍然相同您声明
ApprovalModel
没有外键。但是,它作为导航属性列在
TechnologyProjectPlanModel
公共列表审批人{get;set;}
;它肯定应该有一个FK,除非EF模型和您的SQL不一致。啊,非常感谢。我想出了另一个解决方法,但是[NotMapped]会快得多,谢谢!实体是否假设模型的任何集合都是导航属性?所有的假设都基于这里详细描述的约定类:这就是我最后要做的。我想手动执行此操作,只是为了避免循环引用,因为它被序列化为JSON,但我继续并为此创建了一个viewmodel。谢谢你的链接,但是,应该有助于很多前进!是的,Ayende有一篇关于这个主题的帖子,投影到ViewModel绝对是避免这个问题的方法。
foreach (TechnologyProjectPlanModel result in results)
{
    //get approvers for plan
    int id = result.Id;

    try
    {
         List<ApprovalModel> approvers = db.ApprovalModels.Where(m => m.FormId == result.Id).Select(m => m).ToList();   //ERROR HERE

         if (approvers != null)
         {
             result.Approvers = approvers.ToList();
         }
    }
    catch (Exception e)
    { 
    }
}
public class ApprovalModel
{
    [Key]
    public int Id { get; set; }

    public int ApprovalProcessId { get; set; }
    public int FormId { get; set; }
    public int UserId { get; set; }
    public bool? Approved { get; set; }
}
public class TechnologyProjectPlanModel
{
    [Key]
    public int Id { get; set; }

    public int FormId { get; set; }
    public int UserId { get; set; }
    public string FormType { get; set; }
    public int Status { get; set; }
    public int Hidden { get; set; }
    public DateTime DateSubmitted { get; set; }
    public DateTime DateFinalized { get; set; }

    public List<QuoteUploadsModel> Quotes { get; set; }
    public List<ApprovalModel> Approvers { get; set; }

    [Required]
    [Display(Name = "Please Select Your School")]
    public string School { get; set; }

    [Required]
    [Display(Name = "Requestor")]
    public string Requestor { get; set; }

    [Display(Name = "Title")]
    public string Title { get; set; }

    [Required]
    [DataType(DataType.PhoneNumber)]
    [Display(Name = "Phone Number")]
    [Phone]
    public string PhoneNumber { get; set; }

    [Required]
    [DataType(DataType.EmailAddress)]
    [Display(Name = "Email Address")]
    [EmailAddress]
    public string Email { get; set; }

    [Required]
    [Display(Name = "Project Title")]
    public string ProjectTitle { get; set; }

    [Display(Name = "Requested Completion Date")]
    public DateTime RequestedCompletionDate { get; set; }

    [Required]
    [Display(Name = "Project Description")]
    public string ProjectDescription { get; set; }

    [Display(Name = "Teacher/Room Number")]
    public string TeacherGroup { get; set; }

    [Display(Name = "1")]
    public bool Grade1 { get; set; }
    [Display(Name = "2")]
    public bool Grade2 { get; set; }
    [Display(Name = "3")]
    public bool Grade3 { get; set; }
    [Display(Name = "4")]
    public bool Grade4 { get; set; }
    [Display(Name = "5")]
    public bool Grade5 { get; set; }
    [Display(Name = "6")]
    public bool Grade6 { get; set; }
    [Display(Name = "7")]
    public bool Grade7 { get; set; }
    [Display(Name = "8")]
    public bool Grade8 { get; set; }
    [Display(Name = "9")]
    public bool Grade9 { get; set; }
    [Display(Name = "10")]
    public bool Grade10 { get; set; }
    [Display(Name = "11")]
    public bool Grade11 { get; set; }
    [Display(Name = "12")]
    public bool Grade12 { get; set; }
    [Display(Name = "Kindergarten")]
    public bool Kindergarten { get; set; }

    [Display(Name = "Describe how this plan will be continued if events cause programs or equipment to no longer be available.  For example, if equipment purchased needs repair what funding source will be used for repair or replacement?  For programs that have annual subscription fees, what funds will be used to continue the program from year to year?")]
    public string Sustainability { get; set; }

    public bool MultipleFundingSource { get; set; }

    [Required(ErrorMessage="*")]     
    [Display(Name = "Funding Source")]
    public string FundingSource1 { get; set; }

    [Required(ErrorMessage = "*")]
    public string FundingSource2 { get; set; }

    [Required(ErrorMessage = "*")]
    public string FundingSource3 { get; set; }

    [Required(ErrorMessage = "*")]
    public string FundingSource4 { get; set; }

    [Required(ErrorMessage = "*")]
    public string FundingSource5 { get; set; }

    [Required]
    [Display(Name = "Total Estimated Project Costs:")]
    public float TotalEstimatedProjectCosts { get; set; }

    //----------------------Additional Information

    [Display(Name = "Additional Comments:")]
    public string AdditionalComments { get; set; }

    [Display(Name = "Additional Supporting Documents:")]
    public string AdditionalSupportingDocuments { get; set; }
}
public class ApprovalModel
{
}

public class TechnologyProjectPlanModel
{
    public List<ApprovalModel> Approvers { get; set; }
}
[NotMapped]
public List<ApprovalModel> Approvers { get; set; }
public class ApprovalModel
{
    public int TechnologyProjectPlanModelId { get; set; }

    // ForeignKey attribute usually not necessary unless you need to tell EF
    // about a property that doesn't follow the usual "{OtherEntityName}Id"
    // naming convention.
    [ForeignKey("TechnologyProjectPlanModelId")]
    public TechnologyProjectPlanModel TechnologyProjectPlanModel { get; set; }
}

public class TechnologyProjectPlanModel
{
    public List<ApprovalModel> Approvers { get; set; }
}