LINQ vs DataTable/DataView: A Lesson for Agility Developers


This article is a re-post of an older article posted in November, 2010 by Joel Varty


I did some tests last night just to see if there was anything wrong with querying DataTable and DataViews using LINQ.

The same queries done using a DataTable.Select() and a LINQ query over the same table took anywhere from 50 to 100 times longer when using LINQ.  Yikes.

This performance gets WORSE as the table gets more rows and more columns.

SO PLEASE when you are doing any queries of data using DataTables, please do DataTable.Select() to get your data, then IF YOU MUST, convert it to objects after that.

I know, there are cases where having the data as objects instead of DataRows makes life way easier, and I have no problem with converting DataRows to objects, especially seeing as you NEED to do this when outputting JSON.  That being said, make sure that you convert as small a number of objects as possible when doing this, and know that any queries you do over those objects using LINQ are going to be slower than the equivalent DataTable.Select() calls.

0 out of 0 found this helpful



Please sign in to leave a comment.