views:

76

answers:

2

Asp.net, c#, vs2008, sqlserver 2005.

I am filling a DataTable in the data access layer with data from a sqlserver stored procedure.

Best Practices Question –

Is it ok to pass the DataTable to the business layer and use the DataTable from the business layer for an ObjectDataSource in the presentation layer,

or

Should I transfer the data in the data table into a List and use the List for an ObjectDataSource in the presentation layer?

If I should transfer the data to a List, should that be done in the data access layer or the business layer?

Does it make a difference if the data needs to be edited before being displayed?

+1  A: 

I would say it is OK to pass the DataTable to the business layer and that it is a good practise. You can minimize the places that the data layer is being called and call the presentation layer only from the business layer.

It is a good practice to make sure that the presentation layer is not aware of the data layer in case you wish to replace the data layer.

Transferring to a list is good to do in the data layer as then the business layer does not have to be aware of the underlying data in the data layer.

What do you mean by edited before displayed? Is there any business logic on how to edit the data source then it should be in the business layer.

Perhaps you should consider a service layer. A service layer acts as a layer between business and data so that you can change the datalayer without changing the business layer, it also performs some validation: http://www.asp.net/(S(pdfrohu0ajmwt445fanvj2r3))/learn/mvc/tutorial-38-cs.aspx

Oskar Kjellin
+1  A: 

My opinion:

  • It's OK to use DataTable in the UI, a GridView and other controls can be binded easily to its data through an ObjectDataSource, and paging and sorting is automagic. Paging and sorting must be programmed if you bind to a IList.

  • It's NOT OK to use DataTable in the Business Layer, the previous "layer" should transform the DataTable in a domain object. The Business Layer should talk to Orders, not OrdersDataTable.

  • The creation of the DataTable should be, for example, a UI responsability, not a Business responsability.

  • Totally, you should use a "Service Layer" to wrap the "Business Layer".

bloparod