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 POCO
s, so I have two choices :
- Connected
POCO
s - Disconnected
POCO
s
If I use disconnected POCO
s 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
State
in client side - When I want save changes to DB, I have to sync client side
POCO
'sState
withDbContext
entity'sState
. - During adding
POCO
s to newly createdDbContext
, I have to control to prevent adding two entities with same key to theDbContext
.
So, it seems normal, to use Connected POCO
s, but in this situation I think I have the following challenges:
- If I want to manage lifetime of my
DbContext
using anIoC
container, in a multiuser environment, and keep alive theDbContexts
for all users from time their gettingPOCO
s 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
POCO
s in a my multitier application? - which config should I use to manage lifetime of my
DbContext
s usingIoC container
s 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?