InsertOnSubmit versus Add versus Attach

InsertOnSubmit versus Add versus Attach

Postby afva » Wed 19 Aug 2009 10:12

Hello,

Can somebody tell me the difference between then methods:
db.Customers.insertOnSubmit() ;
db.Customers.Add();
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
db.Customers.Add(cust);

doens't work for me. I cannot use the last statement:
db.Customers.Add(cust);
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
afva
 
Posts: 39
Joined: Thu 13 Aug 2009 21:22

Postby 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.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16


Return to dotConnect for Oracle