A DataSet is a collection of data.
Most commonly a DataSet corresponds to the contents of a single database table, or a single statistical data matrix, where every column of the table represents a particular variable, and each row corresponds to a given member of the DataSet in question. The DataSet lists values for each of the variables, such as height and weight of an object, for each member of the DataSet. Each value is known as a datum. The DataSet may comprise data for one or more members, corresponding to the number of rows.
Our experience tells that using DataSets in projects is not the best solution. But in some situation, it could be the case when, for example, we need a project for support and there won't be another way except - to work with DataSets.
The term DataSet may also be used more loosely, to refer to the data in a collection of closely related tables, corresponding to a particular experiment or event.
List instead of DataSet
DataSet are not useful. Because property name should be as the string.
var age = Convert.ToInt32(members[i]["MemberAge"].ToString());
But if someone will change column name - application still build without errors but at runtime you will receive an exception "Column abc does not belong to the table?"
And this is not quite easy to work with DataSets during Debugging and it is not very useful. Plus there are some other minor reasons why we should not use DataSet.
Instead of DataSet we can use List. But this is not a method that can convert DataTable (item of DataSet) to List.
There are two solutions how to convert DataTable to List.
- First solution - with Automapper.
Here is the code:
But AutoMapper causing problems for us. Because it could cash Model Type. And you will receive an exception. And this is not fixed atm in AutoMapper.
So we prefer to use the another solution:
- Second solution - custom convert DataTable to List.
Here is the code:
Custom Convert To List
I think no need to explain advantages of List of items in the solution.
Hope this article will be useful for you.
Best Regards. Andrew Tsopych CTO of Diceus