InsertOnSubmit versus Add versus Attach

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
Posts: 39
Joined: Thu 13 Aug 2009 21:22

InsertOnSubmit versus Add versus Attach

Post by afva » Wed 19 Aug 2009 10:12


Can somebody tell me the difference between then methods:
db.Customers.insertOnSubmit() ;
db.Customers.Attach() ?

I ask this because the next Microsoft example:
Customer cust =
new Customer {
CustomerID = "ABCDE",
ContactName = "Frond Smooty",
CompanyTitle = "Eggbert's Eduware",
Phone = "888-925-6000"
// Add new customer to Customers table

doens't work for me. I cannot use the last statement:
because I don't have the Add-method.

I can use Attach or InsertOnSubmit() but now I am confused on what to use.

Thank you

Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 19 Aug 2009 11:05

The Add() method was renamed to the InsertOnSubmit() method in the LINQ to SQL release, so no Add() suport is available.
As for the Attach() method, it is intended for attaching an existing entity to the context,
so the entity will not be inserted on the SubmitChanges() call.
The attached entity can be updated, but not inserted.
To summarize, I recommend using the InsertOnSubmit() method.

Post Reply