简体   繁体   中英

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. I don't add, update or delete any entity on the DbSet .

If I call SaveChanges afterwards on the DbSet . Does it actually waste resources establishing a connection and other stuff even If I did not made any changes to the 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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