开发者

Is SaveChanges() Necessary with Function Imports (Stored Procedures)?

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, SaveChanges

Persists all updates to the data source and resets change tracking in the object context.

That 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 AddProduct stored procedure. So in your case SaveChanges won't do anything and is not necessary (unless you have other unsaved changes on the ObjectContext of course).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜