DataTable选择与LINQ选择 [英] DataTable Select vs LINQ Select

查看:221
本文介绍了DataTable选择与LINQ选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关 DataTable.Select应该使用 LINQ选择 处理内存中的DataTable?

Any advice on when DataTable.Select should be used versus LINQ Select when dealing with an in-memory DataTable?

我发现LINQ语法更容易,更强大,但我不是确保如果有表现或其他问题使DataTable选择更合适。

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,该API提供已预先填充的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 。选择。我发现它很慢,有一些奇怪的bug。

Based upon personal experience, I try to avoid the Datatable.Select. I find it to be slow and has some odd bugs.

我遇到的一个(Microsoft的证实和记录的)错误是DataTable.Select并不总是在语句中有括号时评估AND条件是否正确。

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)AND(Col< 10)可能无法返回正确答案
,而Col1> 10将正常工作。

For example, (Col1 > 1) AND (Col < 10) can fail to return correct answers, whereas Col1 > 1 AND Col < 10 will work correctly.

此错误不会显示在每台计算机上。在我的情况下,我正在使用的支票在我的开发平台和每个客户端计算机除外。在我发现这个bug之后,我开始转向使用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.

备注:没有长时间的解释,我公司不使用数据库来存储数据。使用DataTable的所有操作涉及从平面文件加载的内存表。所以我不是在说LINQ 2 SQL,而是LINQ to Dataset。

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.

这篇关于DataTable选择与LINQ选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆