I’ve set up a relational db using MSSQL and I’m trying to use the Entity Framework to talk to it, but I’m having some issues. (This is my first EF project).
I’m able to insert data in both the Machines table and the Contacts table using:
_db.AddToMachines(new Machine { MachineModelId = 0, Owner = "Test", SerialNo = "34242341" });
_db.SaveChanges();
But how can I add Contacts to the Machine?


Your
Machinesentity should have a navigation property calledContactsand vice versa. Just add the objects to these properties.Example:
This should insert a new entry in the
Machinestable, a new entry in theContactstable and a new entry in theMachineContactstable referencing the new entries in the two other tables.