Tag: filtering

CollectionViewSource,如何过​​滤数据?

我将ComboBox绑定到实体,但我希望过滤数据。 到目前为止,我尝试了两种方法: “简单”一:通过LINQ to Entities将filter直接应用于ObjectSet 设置过滤事件处理程序,如msdn所述 我对第一种方法感到满意,首先是因为生成到数据库的查询包含WHERE子句,所以不是所有的数据都必须从远程数据库中检索…. 但是,#2方法更灵活,如果在运行时我想更改应用的过滤…我已经按照msdn上的示例,但我得到一个例外,为什么? 所以,我的问题是: 1.哪种方法更好 2.为什么我得到例外? 这是我的代码: private void UserControl_Loaded(object sender, RoutedEventArgs e) { //Do not load your data at design time. if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) { //Load your data here and assign the result to the CollectionViewSource. System.Windows.Data.CollectionViewSource myCollectionViewSource = (System.Windows.Data.CollectionViewSource) this.Resources[“tSCHEDEViewSource”]; // If I use this I get the data […]

LinqfilterList ,其中包含来自另一个List 的字符串值

我有2个List对象(简化): var fileList = Directory.EnumerateFiles(baseSourceFolderStr, fileNameStartStr + “*”, SearchOption.AllDirectories); var filterList = new List(); filterList.Add(“ThisFolderName”); filterList.Add(“ThatFolderName”); 我想过滤fileLst以仅返回包含filterList中任何文件夹名称的文件。 (我希望这是有道理的..) 我尝试了以下表达式,但这总是返回一个空列表。 var filteredFileList = fileList.Where(fl => fl.Any(x => filterList.Contains(x.ToString()))); 我似乎无法理解为什么我什么也得不到,显然我错过了什么,但我不知道是什么。 [编辑] 好的,所以看来我应该更清楚我的问题,我试图在我的fileList中搜索包含来自我的filterList的字符串值的子字符串中的文件。 我已经为那些试图做类似事情的人标记了下面的答案。