views:

703

answers:

3

I'm struggling to think of a good way to use linq2sql, simply I want to use it, but I can't figure out whether it's best to wrap up the linq2sql generated classes inside my model classes providing some form of generic abstract base class / or interface for the common methods on my model classes like add, update, delete etc, or to extend the partial classes that linq2sql generated.

What design have people found most successful? and could you give a quick run down of those said designs?

(I know this is kind of subjective because everyone will have their own best ways, however , I'm not sure if it should be tagged as so. Feel free to edit and make a community wiki if you think it should be.)

+7  A: 

Personally, I wrap Linq2SQL in the repository pattern.

MrJavaGuy
I saw a good example of this in the MVC blogging platform (forget the name of it) done by some microsoft dudes on codeplex. Really helped me understand one way of wrapping it up in a repository pattern :)
Sekhat
Oxite, that's the name :)
Sekhat
awesome example with the oxite, should add a link to it in the answer as a sample
Tom Anderson
A: 

Check this article:

A simple Business Object wrapper for LINQ to SQL

CMS
Looks interesting, I'll give it a read. Thanks.
Sekhat
+3  A: 

Depending on the complexity of your application you may or may not need to use anything other than the generated classes for your ORM. I find that I am able to happily live with the generated classes, extended by partial methods and by wrapping the data context with a wrapper (and possibly extended if I need to add common functionality) to improve testability. Most of my applications are relatively simple from a database perspective, though.

tvanfosson
I'll add to this comment that the company that I now work for has a 200+ table database design, I moved them to LINQ 2 SQL as a "drag-all-tables-in" bandaid until we redesign. The point of my comment is... thigns are working beautifully even in an overly complicated and oversized database :)
Timothy Khouri
For those of you who think I'm kidding: http://www.singingeels.com/Blogs/Nullable/2008/10/01/Plans_to_the_Death_Star_Or_an_AutoGenerated_EDM.aspx
Timothy Khouri