数据表选择VS LINQ选择 [英] DataTable Select vs LINQ Select
问题描述
时的 <一个任何意见href="http://msdn.microsoft.com/en-us/library/system.data.datatable.select.aspx">DataTable.Select应使用与 LINQ选择 时,处理内存中的数据表?
Any advice on when DataTable.Select should be used versus LINQ Select when dealing with an in-memory DataTable?
我发现LINQ的语法更简单,功能更强大,但我不知道是否有这使得一个DataTable选择preferable性能或其他问题。
I find LINQ syntax easier and more powerful, but I'm not sure if there are performance or other issues which make a DataTable select preferable.
(我使用第三方API,它提供了已经pre-填充从数据库中。我需要在内存中进一步筛选的DataTable。)
(I'm using a third party API that provides a DataTable that has been pre-populated from the database. I need to filter that further in-memory.)
推荐答案
基于个人的经验,我尽量避免Datatable.Select。我觉得这是缓慢的,并有一些奇怪的错误。
Based upon personal experience, I try to avoid the Datatable.Select. I find it to be slow and has some odd bugs.
一(确认和微软文档)错误我碰到的是,DataTable.Select并不总是评价和正确的条件时,有括号中的语句。
One (confirmed and documented by Microsoft) bug I ran into was that DataTable.Select doesn't always evaluate AND conditions correctly when there are parenthesis in the statement.
例如,(COL1> 1)和(西小于10)可能无法返回正确的答案, 而COL1> 1和Col&LT; 10将正常工作。
For example, (Col1 > 1) AND (Col < 10) can fail to return correct answers, whereas Col1 > 1 AND Col < 10 will work correctly.
这个错误不会在每台计算机上显示出来。在我来说,我用的是支票运行正常我的开发平台,每一个客户端计算机只有一个除外。之后,我发现了这个错误,我开始转向使用LINQ的选择并注意到,在操作的速度显著增加。
This bug doesn't show up on every computer. In my case the check I was using ran fine on my development platform and every client computer except one. After I discovered this bug I began shifting to using LINQ for selects and noticed a significant increase in the speed of the operations.
附注:如果不进入长的解释,我公司不使用数据库来存储数据。 所有我们的操作与数据表中涉及的平面文件读取内存中的表。所以,我说的不是LINQ 2 SQL,但LINQ到数据集。
Side note: Without going into long explanations, my company doesn't use a database to store data. All of our operations with DataTables involve in memory tables loaded from flat-files. So I am not talking about LINQ 2 SQL, but LINQ to Dataset.
这篇关于数据表选择VS LINQ选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!