gruber gruber - 1 year ago 120
C# Question

adding List of objects to Context in ef

Is it possible to add list of object to Context in entity framework without using foreach addObject ?

thanks for help

Answer Source

Generally you can't do that - you have to do it in a loop. In some cases, however, you can avoid adding every object - specifically, if you have an entity graph and you add the parent node. E.g. if you have a Company object that has a collection of Employees:


/* The following loop is not necessary */
/* The employees will be saved together with the company */
foreach (var employee in company.Employees)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download