views:

69

answers:

2

Hi

I'm creating my first linq based project. The DAL consists of LinqToSQL classes. And the logic layer is just another DLL for keeping it simple.

I wanted to know how do I pass the var object (result of select query) from Login Layer to Presentation Layer?

Should I write my own DTO layer between Login layer and Presentation Layer to transfer the from BLL to Presentation layer or should I serialize the data as XML?

Thanks, Vikas

A: 

I would avoid serializing whenever you have the opportunity to just pass the data as a strongly typed class. And that is what you're going to have to do. I believe when .Net 4.0 comes out you will be able to pass vars, but until then, try returning your query as an IEnumerable instead of a var when you need to pass it to another function.

IE:

public class myClass
{
    public int RecordID { get; set; }
    public string Field1 { get; set; }
}

public void GetDataAndSendToOtherLayer()
{
    using (DBDataContext db = new DBDataContext)
    {
     IEnumerable<myClass> Recs =
      from tab in db.table
      select new myClass
      {
       RecordID = tab.RecordID,
       Field1 = tab.Field1
      };

     OtherLayer.DoSomething(Recs);
    }
}
Michael La Voie
thanks for a quick example :)
Vikas
A: 

Load each row result into an object, place the each object into a Collection and then pass the Collection from the DAL to your BOL where it can then be handled by your business rules before the Collection is passed on to your presentation.

Chris