Contacts must be an ICollection. EF doesn't support IEnumerable as navigation properties, because it's impossible to add items to them.
This also means that you should change the code that creates contacts:
var contacts = viewModel.Contacts.Select(c => new Contact
{
Title = c.Title,
Forename = c.Forename,
Surname = c.Surname,
Phone = c.Phone,
Email = c.Email
}).ToList(); // <= ToList() added
manpreet
Best Answer
3 years ago
I'm using MVC5 and EF6 Code First to create a new
Companyentity that can have manyContactentities. However, only theCompanyrecord is being written to the database.Models:
Controller: