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
InsertOnSubmit versus Add versus Attach
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.
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.