I am trying to understand difference between those two and really need a explanatory simple example for them.
Thanks in advance..
Theres a good Q&A about this on the MSDN forums. Most interesting bit:
InsertAllOnSubmit() simply loops over all the elements in the IEnumerable collection and calls InsertOnSubmit() for each element.
InsertOnSubmit
adds a single record. InsertAllOnSubmit
does the same, but for a set ( IEnumerable<T>
) of records. That's about it.
I found this example of InsertAllOnSubmit() at the very bottom of this page . Just remember to add a using statement for System.Collections.Generic
// Create list with new employees
List<Employee> employeesToAdd = new List<Employee>();
employeesToAdd.Add(new Employee() { EmployeeID = 1000, FirstName = "Jan", LastName = "Jansen", Country = "BE" });
employeesToAdd.Add(new Employee() { EmployeeID = 1001, FirstName = "Piet", LastName = "Pieters", Country = "BE" });
employeesToAdd.Add(new Employee() { EmployeeID = 1002, FirstName = "John", LastName = "Johnson", Country = "BE" });
// Add all employees to the Employees entityset
dc.Employees.InsertAllOnSubmit(employeesToAdd);
// Apply changes to database
dc.SubmitChanges();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.