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

会有一股神秘感。 提交于 2019-12-06 21:08:09

问题


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?
}

回答1:


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).



来源:https://stackoverflow.com/questions/7726913/is-savechanges-necessary-with-function-imports-stored-procedures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!