views:

826

answers:

2

Hi everyboy!

This is my first question, be gentle :). Im working on a project with some kind of distributed architecture.Im trying to do the following:

  1. I have a Data Access Layer that uses LINQ2SQL

  2. I have a Service Layer that is a proxy for the Data Access Layer.

  3. I have a Business Layer that calls the Service Layer for Entities.

    The question is how can I transfer those LINQ2SQL entities to my business Layer?

  4. I want to modify those objects on the business layer and make the travel back with the service layer and re-transform them to LINQ2SQL entities to persist the changes in the DataBase.

    Im sorry if Im asking for some imposible, but Im trying to figure out the beest way but I cant get something intelligent myself :)

    Best Regards! And thanks in advanced!

+3  A: 

Sounds to me like you have 2 different context, the BusinessLogic context and the data access domain. You probably need a transformer/context mapper to convert from one onto another and vice versa.

public class ContextMapper { public BusinessLogic.Customer Convert(DataAccess.Customer customer) {

} public DataAccess.Customer Convert(BusinessLogic.Customer customer) {

}

You could also write these as extension methods if you like

}

Thank you very much! That is a great idea, Should I put this mapper in the BL Layer and have a reference to my LinQ2Sql in the BL as well?
MRFerocius
Since you are using a layered architecture, and you want to make sure you don't have circular references between business logic and DAL (as you want to convert BL objects to DAL objects going downstream and vice versa upstream) you have to consider strategies for dependency inversion.
A: 

It sounds like you need NHibernate or some other more advanced ORM.

Jonathan Parker
But I use Linq2Sql in my DAL, I want to pass objects between layers, to use them in the BL, remember Im using a Service Layer as a Proxy to the Data Access Layer.Im kind of lost :(Thanks for your answer!
MRFerocius
Well the fact that you're using Linq2Sql means you can't separate your DAL from your BL. The entities or domain objects have to be in the same assembly as the Linq data context because that's how linq2sql works.
Jonathan Parker
Unless of course you add a reference to your DAL from your BL. In that case you won't be able to have a service layer.
Jonathan Parker