简体   繁体   English

一次更新许多DbSet对象

[英]Updating many DbSet objects at one time

I am coding a MVC 5 internet application and am using Entity Framework 6. I have an Asset object that can be referenced in many Image objects. 我正在编写MVC 5 Internet应用程序,并且正在使用Entity Framework6。我有一个Asset对象,可以在许多Image对象中引用该对象。

When I edit an Asset object, I need to update a DateTime object that is stored in all referenced Image objects. 在编辑Asset对象时,需要更新存储在所有引用的Image对象中的DateTime对象。 If there are 50 Image objects that need to be updated, can I do this in one database transaction rather than retrieving the Image objects, looping through each Image object, updating the DateTime object and then updating each Image object in the database? 如果有50个需要更新的Image对象,我是否可以在一个数据库事务中执行此操作,而不是检索Image对象,遍历每个Image对象,更新DateTime对象然后更新数据库中的每个Image对象?

Thanks in advance. 提前致谢。

据我所知,如果您循环并更新每个循环,但在循环后调用context.saveChanges(),则它应提交一个事务,因为该事务直到调用saveChanges才完成。

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

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