c# - How should I handle a potentially large number of edits in entity framework? -
i'm using .net 4.5.1 ef 6.0.2 , db-first.
the use case this:
- roughly 50k entities loaded
- a set of these entities displayed user, others required displaying items correctly
- the user may perform heavy actions on entities, meaning user chooses perform 1 action cascades affect potentially hundreds of entities.
- the changes saved database.
the question, then, best way handle this? far i've come 2 different solutions, don't either:
- create dbcontext @ step 1. keep around during whole process, save changes. reason don't this, process might take hours, , far know, dbcontexts should not preserved long.
- create dbcontext @ step 1. discard right after. @ step 4, create new dbcontext, attach modified entities , save changes. big problem see approach how figure out entities have changed? need build changetracker of own able this?
so there better alternative handling this, or should use 1 of solutions above (perhaps changes)?
i go option number 1 - use dbcontext entire process.
the problem have assertion the process might take hours
. don't think want do. imagine happens when user has been editing data 3 hours, , face power blackout before clicking final save. you'll have users running after pitchforks.
you're facing lot of concurrency issues - if 2 users perform same lengthy process @ once? handling collisions after few hours of work going problem, if tell users changes they've made hours ago can't saved. pitchforks again.
so, think should go number 3 - save incremental changes of editing process, user's work isn't lost if bad happens, , can handle collisions if 2 users updating data @ same time.
you want keep incremental changes in separate place, not main tables, because business change hasn't been finalized yet.
Comments
Post a Comment