Click here to Skip to main content

Welcome to the Lounge

   

For lazing about and discussing anything in a software developer's life that takes your fancy.
The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct and please don't post ads.

Technical discussions are welcome, but if you need specific help please use the programming forums.


 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
GeneralRe: Embarrassing.memberwizardzz7 Mar '13 - 8:33 
GeneralRe: Embarrassing.memberColin Mullikin7 Mar '13 - 8:36 
GeneralRe: Embarrassing.memberBig Daddy Farang7 Mar '13 - 8:47 
GeneralRe: Embarrassing.memberthrakazog7 Mar '13 - 9:59 
GeneralRe: Embarrassing.memberAlbert Holguin7 Mar '13 - 8:30 
GeneralRe: Embarrassing.memberBig Daddy Farang7 Mar '13 - 8:44 
GeneralRe: Embarrassing.memberwizardzz7 Mar '13 - 8:50 
GeneralRe: Embarrassing.memberJörgen Andersson7 Mar '13 - 9:16 
GeneralRe: Embarrassing.memberdusty_dex7 Mar '13 - 9:53 
GeneralRe: Embarrassing.memberDalek Dave7 Mar '13 - 10:26 
GeneralRe: Embarrassing.memberDavidCrow7 Mar '13 - 10:33 
GeneralRe: Embarrassing.memberwizardzz7 Mar '13 - 10:52 
GeneralGrrrr.... Learning curvesmvpDave Kreskowiak7 Mar '13 - 5:00 
I added some 50 classes to an EF model, with a single DbContext. This is the first EF model of any size I've ever built, and, of course, I have to learn everything about EF from scratch.
 
After wrapping a couple tables in their own copy of the Repository pattern, I discovered, rather annoyingly, that having multiple instances of said context searching for and adding new items in a relationship presents some problems, because you can't have a single entity tracked by more than one instance of the DbContext managing it. For example, in two seperate repositories, having a context instance creating a new entity and then adding it to a navigation property of a host entity that was dug up by another context instance in a seperate repository. So then how do you get two repositories to share the same context??
 
Hmmm... What to do, what to do...
 
After 18 hours of beating my head against a wall, nearly knocking myself unconscious, trying to come up with a solution to this little problem, the SIMPLEST idea finally crossed my path: Unit Of Work.
 
Why, oh WHY, did this not occur to me sooner!?!?! It's a simple pattern really. Wrap your repositories in a UnitOfWork class that maintains a context instance and hands that context to any repository added to the UnitOfWork class.
 
Grrrrrrrrrr.
 
But, on the plus side, I also found a way to create generic Repository and generic UnitOfWork classes, saving myself from writing about 50+ classes!

GeneralRe: Grrrr.... Learning curvesprotectorPete O'Hanlon7 Mar '13 - 5:04 
GeneralRe: Grrrr.... Learning curvesmvpDave Kreskowiak7 Mar '13 - 5:37 
GeneralRe: Grrrr.... Learning curvesprotectorPete O'Hanlon7 Mar '13 - 6:43 
GeneralRe: Grrrr.... Learning curvesmemberBrady Kelly7 Mar '13 - 7:13 
GeneralRe: Grrrr.... Learning curvesmvpDave Kreskowiak7 Mar '13 - 9:05 
GeneralRe: Grrrr.... Learning curvesmemberEnnis Ray Lynch, Jr.7 Mar '13 - 7:40 
GeneralRe: Grrrr.... Learning curvesmvpDave Kreskowiak7 Mar '13 - 9:10 
JokeRe: Grrrr.... Learning curvesprotectorAspDotNetDev7 Mar '13 - 11:48 
GeneralRe: Grrrr.... Learning curvesmvpDave Kreskowiak7 Mar '13 - 12:38 
GeneralRe: Grrrr.... Learning curvesprotectorAspDotNetDev7 Mar '13 - 13:02 
GeneralRe: Grrrr.... Learning curvesprotectorMarc Clifton7 Mar '13 - 9:37 
GeneralRe: Grrrr.... Learning curvesmemberMark_Wallace7 Mar '13 - 20:22 
GeneralIt's a plot!memberNagy Vilmos7 Mar '13 - 4:33 
GeneralRe: It's a plot!memberThe Bhai7 Mar '13 - 4:37 
GeneralRe: It's a plot!protectorPete O'Hanlon7 Mar '13 - 4:41 
GeneralRe: It's a plot!memberNagy Vilmos7 Mar '13 - 4:44 
GeneralRe: It's a plot!protectorPete O'Hanlon7 Mar '13 - 4:55 
GeneralRe: It's a plot!memberNagy Vilmos7 Mar '13 - 5:13 
GeneralRe: It's a plot!memberThe Bhai7 Mar '13 - 5:01 
GeneralRe: It's a plot!memberNagy Vilmos7 Mar '13 - 5:14 
GeneralRe: It's a plot!memberThe Bhai7 Mar '13 - 5:19 
GeneralRe: It's a plot!memberNagy Vilmos7 Mar '13 - 5:27 
GeneralRe: It's a plot!mentorKeith Barrow7 Mar '13 - 6:29 
GeneralRe: It's a plot!memberwizardzz7 Mar '13 - 8:14 
GeneralRe: It's a plot!memberNagy Vilmos7 Mar '13 - 22:48 
GeneralRe: It's a plot!protectorMarc Clifton7 Mar '13 - 9:38 
GeneralRe: It's a plot!memberNagy Vilmos8 Mar '13 - 3:14 
GeneralRe: It's a plot!memberBergholt Stuttley Johnson7 Mar '13 - 22:19 
GeneralBaconmemberColin Mullikin7 Mar '13 - 3:37 
GeneralRe: BaconprotectorPete O'Hanlon7 Mar '13 - 3:39 
GeneralRe: Baconmemberryanb317 Mar '13 - 3:52 
JokeRe: BaconmemberV.7 Mar '13 - 4:13 
GeneralRe: BaconmemberNagy Vilmos7 Mar '13 - 5:28 
General15 minutes of famememberJohn Simmons / outlaw programmer7 Mar '13 - 3:13 
GeneralRe: 15 minutes of fameprotectorPete O'Hanlon7 Mar '13 - 3:29 
GeneralRe: 15 minutes of famememberColin Mullikin7 Mar '13 - 3:30 
GeneralRe: 15 minutes of fameprotectorPete O'Hanlon7 Mar '13 - 3:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 22 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid