views:

113

answers:

2

I have a business object let's say a Customer. I have a DAL method which brings back a datatable of customers. I have a UI which has a grid which will display a list of customers.

My question is.. is it OK to bind the grid to the datatable, which means the UI will have a reference to System.Data or should the datatable be converted first to an IList and bind that to the grid? The conversion from dt to a list could be a performance hit and I don't see what I would be gaining from using the list instead of going straight with the datatable. Plus I love the datatable visualizer!

What are real advantages of using list of objects instead of datatables of data?

+1  A: 

The only real advantage to using a list of objects over a datatable besides architecture is the strongly typed properties you get (which you can get with typed datasets too). But if you're databinding that doesn't really matter much.

It is perfectly okay to bind to the datatable, and a lot of really good applications use that as their architecture. They will pull back datatables instead of objects from the DAL. I personally don't do this, but there's nothing wrong with it per se.

Max Schmeling
A: 

From a straight binding standpoint, I would just leave it as a datatable since that is what you already have.

The changing to a list is great when you want to iterate over a list of objects instead of over a list of rows. Where it comes in handy is from a Linq standpoint where you want to get the list and further limit it or order it, or if you want to work with specific types instead of a generic list of rows that contains a list of columns.

Solmead