ajhenley (1) [Avatar] Offline
I love Linq, but we have a real commitment to 3-tier (Data, Business, Presentation layer) design here and Linq doesn't seem to lend itself to that.

I need to be able to basically say:

gridview1.datasource = businessobject.getdata()


dataset1 = businessobject.getdata()
gridview1.datasource = dataset1

and Linq doesn't really seem to lend itself to this,
Am a seeing this correctly or am I just clueless?
jwooley (123) [Avatar] Offline
Re: N-Tier design with Linq
There is nothing about LINQ that precludes using it in an N-Tier environment. Remember LINQ is not about working with databases. LINQ to SQL is about working with Databases. LINQ actually facilitates query functionality throughout all of the tiers. Use LINQ to SQL in the data tier to populate your business object collection and send that to your business tier. Your business tier can then add additional functionality through LINQ to Objects.

When working in this form, the trick is managing your DataContext. In a windows environment, you could manage the context on the form level and then pass it to the business object to use as follows:

grid.datasource = businessobject.getdata(context)

In a web or service environment, you would probably keep the context in the data tier and use it just as you would an ADO connection object-creating and destroying it for each atomic action. In that case, you will have to do extra work to manage your attaching, change tracking, and concurrency manually. You can still benefit from the mapping layer to eliminate much of the parameter setting code.