views:

29

answers:

2

What is the optimal way to write the code which interacts with DB using linq2SQL? I need to add some business logic to the entities. So I guess there are two ways:

  1. Write some wrapper class. The main minus is that many fields are the same, so i don't feel it as DRY style.
  2. Add business logic methods to linq2sql entities(these classes are partial) directly
  3. ???
+1  A: 

I'd suggest the biggest benefit of them being generated as partial classes, is that you can extend functionality without the risk of it being stomped by code generation tools (i.e. if the DB schema changes)

Rowland Shaw
+1  A: 

I normally keep my LINQ to SQL domain objects clean from any business logic. I write a separate business layer that contains the business logic. Of course you can mix this and add it to a partial class in your LINQ to SQL objects, as Rowland suggests.

Steven