DataTable vs. BindingList<T>
We were having a discusion today about the merits of using DataTables vs. BindingList<T> (a generic in .NET 2.0) for loading up domain objects into the UI layer (say to display on a grid). My gut feel is telling me DataTables are evil and wrong, but I don't have a lot of hard evidence to choose one over the other. We brainstormed some pros and cons for each and they're listed below.
- DataTable
- Pros
- Simple to implement, not much code needed
- Can use select statements to retrieve values
- Change events are managed within the object automagically
- Display handling for errors built-in (when binding to grids)
- Cons
- Human errors (typos on column names for example) can be exposed at runtime and can't be easily tested
- Need to implement DataViews in order to sort or filter
- Can't test for type safety (or as Scott says DataTables are bowls of fruit)
- Difficult to implement business rules or logic
- Bloatware, lot of extra baggage for features you don't need
- BindingList<T>
- Pros
- No mapping needed
- Strongly typed and type-safe
- Loosly coupled compared to a data table -> mapping columns -> domain object
- More extensible via superclasses, interfaces, etc.
- Cons
- Must iterate through list to find items
- Must implement some mechanism (like a decorator pattern) to respond to change events
- More short term investment to learn and implement
Are we wrong with our list or is there something that you've come across with your dealings with the two approaches?