Is there any valid use case for DataSet and DataTable now that we have Entity Framework? Should DataTable/DataSet be considered obsolete?
If we are going to fetch data from a single database table then DataTable is better choice. While DataSet on the other hand can define DataRelations - which define the relationship between DataTables, much like a foreign key relationship can be set up between tables in a database.
DataSet comprises one or many dataset tables which have the in-memory feature. DataTable holds a single or unit database table that has an in-memory feature. DataSet is formed collectively of datatables. DataTable is composed of multiple rows and columns to have better access to data.
DataReader is used to read the data from the database and it is a read and forward only connection oriented architecture during fetch the data from database. DataReader will fetch the data very fast when compared with dataset.
And then a DataTable alternative is simply a List<Dictionary<string, Cell>> . Let's say you define Rows as public List<Dictionary<string, Cell>> Rows; .
When you know the data schema at compile time then I'd EF would be all you need. However, there are situation where you're getting data from a service and you don't know what the schema/datatypes will be ahead of time. I think DataSet/DataTable would still be useful in that kind of scenario.
I wouldn't go as far as calling them obsolete. I still use datasets when gathering data from several different datasources; xml-files, databases, etc. Then I can use LINQ to DataSet
to manipulate data from the different sources.
I believe there may be other scenarios as well where datasets will be the right fit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With