Is SaveChanges() necessary with function imports (stored procedures)?
Example:
void foo(Product product)
{
// AddProduct is a function import of a stored procedure
entities.AddProduct(product.Name, product.Price, product.Description);
entities.SaveChanges(); // Is this necessary?
}
According to MSDN,
SaveChangesThat is, for any entities that are attached to the context and which you have added, modified or deleted, EF will generate the corresponding SQL code and run it against the database. In your case you are already running SQL code (more or less) directly against the database by calling the
AddProductstored procedure. So in your caseSaveChangeswon’t do anything and is not necessary (unless you have other unsaved changes on the ObjectContext of course).