CodeFirst EF4.1 MVC Against legacy database - Multiplicity conflicts

前端 未结 4 1295
闹比i
闹比i 2020-12-13 17:18

No matter which way I mix it, it gives me errors. I have a feeling I\'m missing something obvious as I keep getting these errors.

One or more validation

4条回答
  •  粉色の甜心
    2020-12-13 17:58

    After searching the web for

    System.Data.Edm.EdmAssociationType: : Multiplicity conflicts with the referential constraint in Role

    It kept comming up with this post so here was my problem and solution:

    I upgraded a large project from ef4.0 to ef4.1 using the vs ef reverse engineering extension. Our mvc app was using metadatatype and partials to decorate ef4.0 objects.

    After removing the files of the metadatatype the project began working.

    The root problem was [Required] attribute as ef poco object had nullable and my metadatatype had [Required] on the same property. Previously was to enforce mvc validation rules and now ef4.1 was using to populate navigation properties. Removing [Required] off metadatatype fixed the problem.

    public partial class AgentAgency
    {
        public long OID { get; set; }
        public long? AgentOID { get; set; }
        public long? AgencyOID { get; set; }
        public string ReinsuranceYear { get; set; }
        public virtual Agency Agency { get; set; }
        public virtual Agent Agent { get; set; }
    }
    
    public class AgentAgencyMetadata
    {
        public Int64 OID { get; set; }
    
        [Required]
        public Int64 AgentOID { get; set; }
    
        [Required]
        public Int64 AgencyOID { get; set; }
    }
    

提交回复
热议问题