DataSets. List instead of DataSet

DataSet

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. 

For example:

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.

 

Solutions

There are two solutions how to convert DataTable to List.

 

  • First solution - with Automapper.

Here is the code:

 

AutoMapper DataSets

AutoMapper

  

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

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

  • e1zhhcfqRdrx

    6/8/2017 4:24:40 PM |

    898956 856202Aw, this became an extremely good post. In thought I would like to set up writing like that in addition - taking time and actual effort to create a fantastic article� but what / points I say� I procrastinate alot by means of no indicates appear to get something completed. 562031

Loading