Have two entities, Customer and Contacts.
I'm saving changes with dbContext.SaveChanges();
- If I enter one row into contactDataGridView (one contact)
* data is saved to db
- If I enter multiple rows into contactDataGridView (many contacts)
* ERROR : Validation failed for one or more entities.
See 'EntityValidationErrors' property for more details.
Quote from SO question Inserting multiple rows into a table using Entity Framework
By default ObjectSet doesn't support adding lists of things, but it's easy to create your own extension method:
public static class ObjectSetExtensions
{
public static void AddObjects<T>(this ObjectSet<T> objectSet, IEnumerable<T> objects)
{
foreach (var item in objects)
{
objectSet.AddObject(item);
}
}
}
Is that answer to my problem ? Do I need to create list as the answer says?
If yes, how to do that?