0

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?

2
  • Post some code please, as described the question is too broad/unclear. Commented Jan 20, 2014 at 16:49
  • I don't have any insert/update code. I use auto generated from entity framework. Please tell me what code do I need to put here. Commented Jan 20, 2014 at 17:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.