How do I transfer data when using LINQ as a LAD?


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

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.


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