Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Strongly Typed Datasets improve performance?

Where I work we're finally coming around to the idea of using strongly typed datasets to encapsulate some of our queries to sqlserver. One of the idea's I've been touting is the strength of the strongly typed column's, mainly for not needing to cast any data. Am I wrong in thinking that strongly-typed-datasets would improve performance in the following situation where there could be potentially thousands of rows?

old way:

using(DataTable dt = sql.ExecuteSomeQuery())
{
    foreach (DataRow dr in dt.Rows)
    {
        var something = (string)dr["something"];
        var somethingelse = (int)dr["somethingelse"];
    }
}

new way:

MyDataAdapter.Fill(MyDataset);
foreach (DataRow dr in MyDataset.MyDT.Rows)
{
    var something = dr.Something;
    var somethingelse = dr.SomethingElse;
}

If the properties are really just doing the casting behind the scenes, I can see how there wouldn't be any speedup at all; perhaps it would take even longer then before with the overhead of the function call in the first place.

Are there any other performance strengths / weaknesses of using DataSets we should know about?

Thanks!

like image 728
Nicholas Mancuso Avatar asked Nov 30 '22 20:11

Nicholas Mancuso


1 Answers

I'm not sure if there will be any performance improvements using the strongly typed datasets, however you get the added type safety, and with it compiler errors when you mistype a field name, for example.

There's an article in MSDN magazine about them, to quote a line in it:

The speed in accessing a typed DataSet is comparable to the faster techniques in accessing an untyped DataSet (since a typed DataSet is just a layer over an untyped DataSet) and the readability of the typed DataSet is the best

Also, as Stuart B pointed out, the Intellisense alone makes it worthwhile.

like image 144
Patrick McDonald Avatar answered Dec 09 '22 20:12

Patrick McDonald