DataView.RowFilter VS DataTable.Select()与DataTable.Rows.Find() [英] DataView.RowFilter Vs DataTable.Select() vs DataTable.Rows.Find()

查看:625
本文介绍了DataView.RowFilter VS DataTable.Select()与DataTable.Rows.Find()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面的code:

Dataview someView = new DataView(sometable)
someView.RowFilter = someFilter;

if(someView.count > 0) {  …. }

相当多的物品说Datatable.Select()是比使用DataViews的更好,但这些都是之前VS2008

Quite a number of articles which say Datatable.Select() is better than using DataViews, but these are prior to VS2008.

解决:数据视图的大型记录
性能差的奥秘 DataRecord的阵列与数据视图:在性能一个显着的差异

Solved: The Mystery of DataView's Poor Performance with Large Recordsets
Array of DataRecord vs. DataView: A Dramatic Difference in Performance

谷歌搜索关于这个主题,我发现了一些物品提Datatable.Select()本身是相当越野车(不知道这个)和不佳的各种方案。/论坛主题

Googling on this topic I found some articles/forum topics which mention Datatable.Select() itself is quite buggy(not sure on this) and underperforms in various scenarios.

在此(最佳实践ADO.NET )在MSDN主题是建议,如果还有就是findrows(),或者找到一个数据表中定义主键()Datatable.Select()。

On this(Best Practices ADO.NET) topic on msdn it is suggested that if there is primary key defined on a datatable the findrows() or find() methods should be used insted of Datatable.Select().

本文 (.NET 1.1)基准所有的三种方法加上一对夫妇更。但是,这是1.1的版本,所以不知道这是有效的还是现在。 Accroding这个DataRowCollection.Find()优于所有的方法和Datatable.Select()优于DataView.RowFilter。

This article here (.NET 1.1) benchmarks all the three approaches plus a couple more. But this is for version 1.1 so not sure if these are valid still now. Accroding to this DataRowCollection.Find() outperforms all approaches and Datatable.Select() outperforms DataView.RowFilter.

所以,我对什么可能是在寻找行的数据表,最好的办法很困惑。或者没有一个统一的好办法做到这一点,多解存在根据方案?

So I am quite confused on what might be the best approach on finding rows in a datatable. Or there is no single good way to do this, multiple solutions exist depending upon the scenario?

推荐答案

Aseem,

您正在寻找的在发现行的DataTable最好的方法,所以我首先要问:最好是什么?我认为,任何技术都有场景,它可能更适合然后其他人。

You are looking for the "best approach on finding rows in a datatable", so I first have to ask: "best" for what? I think, any technique has scenarios where it might fit better then the others.

首先,让我们来看看 DataView.RowFilter :一个数据视图在数据绑定一定的优势。它非常鉴于为本所以它有强大的排序,筛选或搜索功能,而造成一些开销,并没有针对性能进行优化。我会选择 DataView.RowFilter 更小的记录和/或您采取的其他功能的优势(如,一个直接的数据绑定到视图)。

First, let's look at DataView.RowFilter: A DataView has some advantages in Data Binding. Its very view-oriented so it has powerful sorting, filtering or searching features, but creates some overhead and is not optimized for performance. I would choose the DataView.RowFilter for smaller recordsets and/or where you take advantage of the other features (like, a direct data binding to the view).

有关数据视图,您可以在旧帖子阅读,仍然适用大多数的事实。

Most facts about the DataView, which you can read in older posts, still apply.

其次,你应该preFER DataTable.Rows.Find DataTable.Select ,如果你想只一个单一的打击。为什么? DataTable.Rows.Find返回只有一行。从本质上讲,当你指定主键,一个二叉树创建。这具有与它相关的一些开销,但极大地加快了检索。

Second, you should prefer DataTable.Rows.Find over DataTable.Select if you want just a single hit. Why? DataTable.Rows.Find returns only a single row. Essentially, when you specify the primary key, a binary tree is created. This has some overhead associated with it, but tremendously speeds up the retrieval.

DataTable.Select 比较慢,但能来,如果你有多个标准,不关心索引或者没有索引的行非常方便:它可以找到基本的一切,但为没有针对性能进行优化。从本质上讲,DataTable.Select必须遍历整个表,每条记录比较,你传入的标准。

DataTable.Select is slower, but can come very handy if you have multiple criteria and don't care about indexed or unindexed rows: It can find basically everything but is not optimized for performance. Essentially, DataTable.Select has to walk the entire table and compare every record to the criteria that you passed in.

我希望你能找到这个小概述帮助。

I hope you find this little overview helpful.

我会建议看看 这篇文章 ,这是有关业绩的问题妄作。此帖包含从它的一些报价。

I'd suggest to take a look at this article, it was helpful for me regarding performance questions. This post contains some quotes from it.

一个小更新: 顺便说一句,这似乎有点超出你的问题的范围,但它几乎总是最快的解决方案做了过滤和搜索上的后端。如果你想的简单,并具有 SQL服务器作为后端和.NET3 +客户端,去LINQ到SQL。搜索LINQ的对象是非常舒适,并创建这是在服务器端执行查询。尽管LINQ到对象也是一个很舒适,但也比较慢的技术。如果你不知道已经......

A little UPDATE: By the way, this might seem a little out of scope of your question, but its nearly always the fastest solution to do the filtering and searching on the backend. If you want the simplicity and have an SQL Server as backend and .NET3+ on client, go for LINQ-to-SQL. Searching Linq objects is very comfortable and creates queries which are performed on server side. While LINQ-to-Objects is also a very comfortable but also slower technique. In case you didn't know already....

最好的问候, 托马斯

这篇关于DataView.RowFilter VS DataTable.Select()与DataTable.Rows.Find()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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