With linq2sql, is it possible to have a 3 tierd app or so I have to pass the dbcontext around since its an expensive call?
views:
15answers:
1
+2
A:
A common thing to do is to create a Repository class which implements IDisposable, and have the context inside the repository. When it gets created you instantiate your context, and then dispose it when the repo gets disposed.
That way you can use it throughout the life of your repository.
Joseph
2009-11-18 19:27:20
I would go one step further and say that the lifetime of the datacontext should tied to a unit of work, not the repository it's in. Instantiate and dispose a new datacontext for every unit of work.
Eric King
2009-11-18 19:37:44
@eking absolutely. I would recommend using your repository in a unit of work pattern, for sure.
Joseph
2009-11-18 19:39:15
@Joseph, we're on the same page. :-) +1
Eric King
2009-11-18 19:42:05
is a unit of work a request?
mrblah
2009-11-18 19:59:11