Entity Framework Update Methods
I have a few entities I'd like to update at the same time. However I'd like to write individual update methods in each classes partial class file, for each entity and call them all at the same time. For example:
public sub UpdateEntity1()
...
end sub
public sub UpdateEntity2()
...
end sub
public sub UpdateEntity3()
...
end sub
public sub UpdateAll()
UpdateEntity1()
UpdateEntity2()
UpdateEntity3()
end sub
My question is how do I manage the object context? do I create one object context in the class I'm calling UpdateAll(), then pass it as a parameter to each individual update method? Or do I create a new context for each Update? I'd like to use the same context because the object are related, and this would decrease the db calls to update all 开发者_运维知识库the records.
I would do as you said and pass the context as a parameter. You may need to make sure your changes get tracked hough if the object gets detached from its original context.
精彩评论