I am developing a multi tier desktop application(Onion architecture), with a WinForm Project as UI, and I used EF code first to access my DB, and for my Domain models, I want to use POCOs, so I have two choices :
- Connected
POCOs - Disconnected
POCOs
If I use disconnected POCOs I have to do a lot of stuff outside of EF and do not use EF features, because:
- I have to save and manage entity's
Statein client side - When I want save changes to DB, I have to sync client side
POCO'sStatewithDbContextentity'sState. - During adding
POCOs to newly createdDbContext, I have to control to prevent adding two entities with same key to theDbContext.
So, it seems normal, to use Connected POCOs, but in this situation I think I have the following challenges:
- If I want to manage lifetime of my
DbContextusing anIoCcontainer, in a multiuser environment, and keep alive theDbContextsfor all users from time their gettingPOCOs to time that saving back their changes to DB, it take large amount of server memory, I think, and it isn't efficient. - I want to save below related graph of my entities in one transaction
I have these questions:
- How can I use connected
POCOs in a my multitier application? - which config should I use to manage lifetime of my
DbContexts usingIoC containers in my case? - Is there any way to make(or change) the total graph(in client side) and then pass it to save in
DbContext? - Is there any sample that implement this situations?