Good day.
There is a database of two tables. The structure of the tables is built through the Entity Framework Code First. The structure is as follows:
public class FederationMembers { public Guid ID { get; set; } [Required MaxLength(10)] public string ISO_Code { get; set; } [Required MaxLength(100)] public string Title { get; set; } [Required MaxLength(3)] public string Number { get; set; } } public class LawEnforcement { public Guid ID { get; set; } [Required MaxLength(200)] public string Title { get; set; } [MaxLength(300)] public string Address { get; set; } public FederationMembers SubjectOfFederation { get; set; } } The FederationMembers table is pre-populated at the stage of database initialization. I am trying to make an entry in the LawEnforcement table, and I get an error that the system is trying to add PrimeryKey to the FederationMembers table that already exists. In the SQL profiler is the code
INSERT [tbl].[FederationMembers]([ID], [ISO_Code], [Title], [NUMBER]) VALUES (@0, @1, @2, @3) The code for adding an entry to the LawEnforcement table below
Context context = new Context(); Models.LawEnforcement lea = new Models.LawEnforcement(); lea.ID = Guid.NewGuid(); lea.Title = Request["lea_title"]; lea.Address = Request["address"]; lea.SubjectOfFederation = repo.FederationMembers.Where(c => c.ID.ToString() == Request["lea_fm"]).First(); context.LawEnforcement.Add(lea); context.SaveChanges(); Why does the system try to add an entry to FederationMembers when I try to add an entry to the LawEnforcement.