Reputation: 1939
I'm getting the error
The member with identity 'UsersModel_Group' does not exist in the metadata collection. Parameter name: identity.
when calling the db.UsersModel.Add(SomeModel) method. I checked the controllers and models if there's any problem with namespaces but there's nothing weird that I found. I did change some classes name but there are no errors upon build. Any suggestions?
here are the classes that might be relevant:
public class UsersModel{
public int ID {get; set;}
...
[ForeignKey("GroupID")]
[Display(Name = "Group")]
public virtual GroupModel Group { get; set; }
[Required]
public virtual int GroupID { get; set; }
public virtual List<GroupModel> GroupList { get; set; }
}
public class GroupModel {
public int ID { get; set;}
...
[Required]
public int ID { get; set; }
[Required]
[StringLength(20,ErrorMessage = "The {0} must not exceed {2} characters")]
public string Name { get; set; }
}
Upvotes: 0
Views: 503
Reputation: 34830
If you've changed your model after the database was created you will need to recreate the database. EF Code First stores details of your model inside a metadata table. If this metadata does not match that of your model then you will get an error.
If you don't want to drop your database you can delete the metadata table and then manually make your database changes so that it matches your model.
Upvotes: 1