Why would I want to stay away from DataSets, and what are the alternatives?


I found an interesting discussion here:



DataSets are sub-par amateur solutions to code your Data layer...Stop Using Them and learn to CODE! :)

What is your opinion of DataSets vs. just stubbing out custom classes and working with those? What are other alternatives?

One big drawback is that DataSets are in-memory data structures which means the amount of memory consumed is linear to the amount of records you are returning (i.e. O(n) space complexity). On a server side app this will kill scalability.

If you define a custom class T, then returning IEnumerable<T> from your data access layer enables you to efficiently stream data from your data source (e.g. a Linq to Sql IQueryable provider) with O(1) complexity.

Note: the same problem occurs if you return List<T> or Collection<T> from your data access layer because those are also in-memory structures. I've seen a lot of people do this in the name of elegance without consideration to scalability.