c# - When to use more than one DbContext in the Entity Framework? -


dbcontext have properties reflecting different sets of entities in database.

i'm using plugin architecture using mef , have read similar question answering part of question (mef plugins , ef codefirst - how?)

but in core app, have multiple dbcontext (derivatives) group handfuls of entities together. e.g. securitydbcontext configurationdbcontext.

these contexts have few dbset properties in them.

the article referenced provides method have 1 central dbcontext , configure models in plugin libraries. mean there 1 dbcontext whole application , plugins.

i know ef6 support multiple dbcontexts per db - mean can create many dbcontexts needed - including in plugins?

i'm assuming dbcontext can join (in queries) entities defined in irrespective of whether dbcontext same db.

any advice appreciated

i thought i'd share conclusion after reading links other users have provided.

it clear dbcontext classes had created didn't include enough entities found myself using helper functions i'd written detach entity objects other contexts attached other contexts.

the next problem ran against how deal dbcontexts within plugin. plugin may need use "core" entity define own.

deciding use single dbcontext whole system, using mef , solution question (mef plugins , ef codefirst - how?) able manipulate single dbcontext handle additional entities defined in plugin.

all working @ present, although i'd read poor performance of large dbcontexts - moving forward, depending on number of entities , performance of single dbcontext may refactor break series of smaller dbcontexts , have single dbcontext in managing database sync.

hope helps same question


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -