简体   繁体   English

如果没有进行任何更改,Entity Framework的DbContext是否会保存更改?

[英]Does Entity Framework's DbContext save changes if no changes were made?

I could not find an answer on the Internet. 我在互联网上找不到答案。

Let's suppose I have a DbContext , and I just select all the entities from it. 假设我有一个DbContext ,我只是从中选择所有实体。 I don't add, update or delete any entity on the DbSet . 我不添加,更新或删除DbSet上的任何实体。

If I call SaveChanges afterwards on the DbSet . 如果我之后在DbSet上调用SaveChanges Does it actually waste resources establishing a connection and other stuff even If I did not made any changes to the DbSet ? 它是否真的浪费资源建立连接和其他东西即使我没有对DbSet做任何更改?

Is it smart enough to detect if a change was made or not, and behave differently? 是否足够智能来检测是否进行了更改,并且行为方式不同?

It uses EntityState to determine that there is nothing to commit and so does not waste resources. 它使用EntityState来确定没有任何提交,因此不会浪费资源。

http://msdn.microsoft.com/en-us/library/system.data.entitystate%28v=vs.110%29.aspx http://msdn.microsoft.com/en-us/library/system.data.entitystate%28v=vs.110%29.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM