Uses of DataSet In .NET CORE

Mohammad Shahjada Sagor
3 min readApr 30, 2020

--

System.Data.DataSet is part of .NET Framework. It represents an in memory cache of data. DataSet consists of collection of DataTable. DataSet Can be strongly typed XSD (XML Schema Definition).

To retrieve data from a data source or save data into a data source .NET framework provides DataAdapter class uses Fill to changes data in the DataSet to match the data in the data source and Update is used to change the data in the data source to match the data in the dataset.

Edit Project File

In console application .NET core appsettings.json doesn’t come up by default. So I’ve to add it manually & changes project file to get appsettings.json in the output directory at build time.

Pre-requisite

You have to ensure that following packages are installed from NuGet Package Manager.

using Microsoft.Extensions.Configuration;

Explanation

In main function BuildConfiguration() is used to configuration builder. By which we can add appsettings.json and get the connection string of the datasource.

IDataPlot.cs is an interface & DataPlotService.cs class implements the interface.

IDictionary<string, List<object>> GetDataSet(params object[] objs) function takes object as you want from data set FIFO basis and returns result as key, value pair. where value is the representation list as you provided in function input parameters.

As I want to return dataset from data source like:

Entity that should be used to fill in the dataset
Data Source Value

Implementation of Interface

Normally DataSet returns DataTable with default naming convention like Table, Table1, Table2….incremental way. But our current data source returning only two tables as we mentioned above.

The function DataSetExplorer takes two arguments as input parameter one is the data set that already fill from the data source and another one is mapping objects which is used as FIFO basis to map with DataTables.

The function DataReaderExplorer takes also two arguments as input parameter one is DataTableReader and another one is mappingObjects. From DataTableReader we will fetch each row and map with provided mapping object if common property & data types are matched with fetched rows. By using this steps we make a list (mapping object type) for each data table.

Summary/ Results

Here is the outcome, As we provided in the function GetDataSet(new SummaryData(), new Product()) from the main function.

  1. No of list count 2. As data source returns two tables.
  2. First one for SummaryData & second one for Product.
first resultant data from the dataset
second resultant data from the dataset

Thanks for reading. If you have any queries or feedback then feel free to let me know.

--

--