views:

49

answers:

4

Hi, I would like to implement LINQ IN ASP.NET for filter required data from datatable. I have doubt that what is right place. I have following options

  1. At presentation layer *.aspx.cs
  2. At our Business layer.
  3. At our Data base layer, where query for database happen which is return as a datatable to business layer. Business layer then return the result to presentation layer.

Can anyone please help me to find out right place for LINQ because now i have to further filter data from datatable as per user selecter filters.

Please help?

+3  A: 

Linq can be used in all the layers but, the best place to make these sorts of manipulation is in the Business layer. This will make the code more maintainable and easily shared for future use in other pages.

Alexandre Brisebois
+1  A: 

If you are just filtering your data using linq (e.g linq to objects, linq to datasets) - you can use it in Business layer.

If you are doing linq to sql and doing data manipulation then you can use it Data Access layer. But if it is too small app then you can use it in any layer you want.

Krunal
A: 

Why not try the ASP .NET MVC framework instead? It is built on top of ASP .NET (so you benefit from all its features) plus you have the layers in place with a fairly good separation of concerns. As other have replied, the best option theory-wise would be to place the code in the Business layer. That is the Model part of the ASP .NET MVC structure.

Give it a try and your answer will arise naturally.

vbocan
A: 

Hemant, I think that your critical statement is "I have to further filter data from datatable as per user selecter filters." The initial data selection should obviously come from your business layer to A) isolate the database from the UI and B) to implement any business-specific rules to "condition" the data before it is delivered to the UI.

Given that you are just selecting subsets based on User interactions, I think it entirely reasonable to put the logic in the UI. Indeed, this may well be the only condition where it makes sense to perform data-centric operations in the UI.

With that being said, I've implemented user based filtering in a specialized class in my Business Logic Layer. This is reasonable for me because all of the user filtering has a pretty specific focus (it doesn't range across the entire database).

So - here is your choice. If you really are just implementing user filters and different pages have different kinds of filters based on the data that they show then you have a reasonable argument for placing the filtering logic (only) in the UI layer. You are after all, implementing UI interaction code! However, if there is a clean way to encapsulate the range of filters your users are allowed to request in a separate class that all pages use, then I would advocate placing that class in your Business Logic Layer.

Mark Brittingham