The error code given was quite vague so I'm having a hard time tracing the error. I'm just assuming that it has something to do with how I related my table?
The error code is this:
{"The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_dbo.LGMembers_dbo.Lifegroups_LifegroupID\".
The conflict occurred in database \"aspnet-COGSimple-20140204091131\", table \"dbo.Lifegroups\", column 'LifegroupID'.\r\nThe statement has been terminated."}
From this post INSERT statement conflicted with the FOREIGN KEY constraint, It said that:
The way a FK works is it cannot have a value in that column that is not also in the primary key column of the referenced table
However, my tables are referenced in such a way that every fk is linked to a Primary Key.
The tables affected:
public class Lifegroup
{
[Key]
public int LifegroupID { get; set; }
[Display(Name = "Lifegroup Name")]
public string LGName { get; set; }
[Display(Name = "Lifegroup Type")]
public string LGType { get; set; }
public DateTime DateCreated { get; set; }
public int LGLeaderID { get; set; }
[ForeignKey("LGLeaderID")]
public virtual LGLeader LGLeader { get; set; }
}
public class LGLeader
{
[Key]
public int LGLeaderID { get; set; }
public string UserID { get; set; }
[ForeignKey("UserID")]
public virtual User User { get; set; }
}
public class LGMember
{
[Key]
public int LGMemberID { get; set; }
public string UserID { get; set; }
public int LifegroupID { get; set; }
[ForeignKey("UserID")]
public virtual User User { get; set; }
[ForeignKey("LifegroupID")]
public virtual Lifegroup Lifegroup { get; set; }
}
Thank you very much!
Edit:
The error comes from a db.SaveChanges() when trying to insert data to LGMember.