如何使 ObjectResult 可过滤
看起来应该很简单,但我显然太笨了,无法弄清楚。我使用简单的 ObjectQuery
获取 ObjectResult;这只是数据表中的几条记录。我将其分配给 CollectionViewSource
Source 属性。然后,我查看 CollectionView
的 View 属性,发现 CanFilter
和 CanSor
t 均为 false。当我将 DefaultView 作为 BindingListCollectionView 获取时,它显示 CanCustomFilter
为 false。由于这些是只读的,我无法更改这些值。现在,我想对检索到的数据设置过滤器(或排序),而无需返回 SQL Server,但我一生都找不到一种方法来获取这些属性设置为 true 的数据。
我尝试使用 ObjectResult.AsQueryable
,结果确实有 CanFilter
和 CanSort
true,但这将视图类型从 < code>System.Windows.Data.BindingListCollectionView 到 MS.Internal.Data.EnumerableCollectionView
中,我找不到一种方法来转换它EnumerableCollectionView
返回到 BindingListCollectionView
。
任何指示将不胜感激。
It seems like it should be simple, but I'm apparently too dense to figure it out. I'm getting an ObjectResult using a simple ObjectQuery
; it's just a few records in the data table. I assign it to a CollectionViewSource
Source property. I then look at the View property of the CollectionView
and see that CanFilter
and CanSor
t are both false. When I get the DefaultView as a BindingListCollectionView, it shows that the CanCustomFilter
is false. Since these are read-only, I cannot change the value(s). Now I'd like to set a filter (or sort) on the retrieved data without making a trip back to SQL Server, but for the life of me I cannot find a way to get the data with these properties set true.
I tried using ObjectResult.AsQueryable<T>()
and the result DOES have CanFilter
and CanSort
true, but that changes the View type from System.Windows.Data.BindingListCollectionView
into MS.Internal.Data.EnumerableCollectionView
and I cannot find a way to cast that EnumerableCollectionView
back into a BindingListCollectionView
.
Any pointers would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这种偏差的主要原因是
BindingListCollectionView
无法过滤或排序任何IQueryable
对象(不知道为什么),尽管在设置上执行查询源属性
。最简单的方法是使用ToList()
方法,该方法执行查询,但是形成的List
可以通过BindingListCollectionView
进行排序和过滤代码>I think the main reason of such deviation is that
BindingListCollectionView
can't filter or sort anyIQueryable
objects (don't know why), in spite of execution of query on settingSource property
. The simpliest way is to useToList<T>()
method, which executes query, but formedList<T>
can be sorted and filtered byBindingListCollectionView