0

I am getting the weirdest error. I'm using code first to initial my database. I have 2 entities that have a many to many relationship. If I attempt to initialize either ICollection in the constructor I get the following error when trying trying to use the context to add a value (initially build the database vie entity framework)

The number of members in the conceptual type 'ClubCraftManager.DataAccess.Club' does not match with the number of members on the object side type 'ClubCraftManager.Model.Models.Club'. Make sure the number of members are the same.

public class Club
    {
        public Club()
        {
            this.ClubCrafters = new List<Crafter>();
        }

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public virtual Guid ClubIdGuidId { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public bool IsActive { get; set; }    
        public Guid ClubMangerId { get; set; }    
        [ForeignKey("ClubMangerId")]
        public virtual Crafter ClubManager { get; set; }    
        public virtual ICollection<Crafter> ClubCrafters { get; } 
    }

If I leave the classes as the following no error, but I hate not initialing Collections and or lists, leaves yourself open for null values later on....

public class Club
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public virtual Guid ClubIdGuidId { get; set; }    
        public string Name { get; set; }    
        public string Description { get; set; }    
        public bool IsActive { get; set; }          
        public Guid ClubMangerId { get; set; }    
        [ForeignKey("ClubMangerId")]
        public virtual Crafter ClubManager { get; set; }    
        public virtual ICollection<Crafter> ClubCrafters { get; set; } 
    }

Any idea what's going on here...?

Gert Arnold
  • 105,341
  • 31
  • 202
  • 291
jaywebguy
  • 43
  • 6
  • Pretty common error when you edit the EDMX file outside VS. Pretty sure you're not doing code-first. Google the error, its super common. http://stackoverflow.com/questions/2096399/number-of-members-in-conceptual-type-does-not-match-with-number-of-members-on-ob – Nico May 24 '16 at 04:02
  • Trust me it's code first, I'm not touching EDMX files at all. I update my class, do a clean on the solution, then run. As soon as I try to add to the Club object on the context I get the error... – jaywebguy May 24 '16 at 04:09
  • Are you using lazy loading? If not, maybe removing the `virtual` keyword would do the trick –  May 24 '16 at 19:58

0 Answers0