.net - 处理过滤数据时如何在领域中进行过滤
问题描述
我已经尝试在领域集合中过滤 IQueryable<>,如下所示:
public class Configuration
{
public bool IsFilter { get; set; }
public IQueryable<Model> ApplyFilter(IQueryable<Model> collection)
{
var filterCollection = collection;
filterMessages = filterMessages.Where(IsFilter || !IsFilter && w.IsFilter);
return filterCollection;
}
}
当我使用时,ApplyFilter
我会得到NotSupportedException
我认为这是因为Configuration
已经处理和收集的对象。
我如何使用类似的过滤器?
解决方案
如果您只是试图通过包含的 bool 属性过滤您的 Realm 模型,那么您将使用 Linq Where ( Where(model => model.IsFilter == IsFilter)
)
例子:
public class Configuration
{
public bool IsFilter { get; set; }
public IQueryable<ItemModel> ApplyFilter(IQueryable<ItemModel> realmQuery)
{
return realmQuery.Where(model => model.IsFilter == IsFilter);
}
}
样品用法:
// Assuming you have an `Configuration` instance already created:
configuration.IsFilter = true;
realmList.ItemsSource = configuration.ApplyFilter(realmList.ItemsSource as IQueryable<ItemModel>);
推荐阅读
- neo4j - Neo4j:我可以在 CQL 中生成运行值吗?
- sql-server - 表的表..使用 SQL 数据透视表为每个表提取唯一字段
- angular - 使用 ActivatedRoute 在返回到 Angular 应用程序中的组件时加载数据
- mongodb - Mongo DB 安全配置
- dictionary - 用标签固定在地图上
- sql - 在两个 SQL Server 实例之间将数据从一个表复制到另一个表
- ruby-on-rails - 在 Rails 中路由时的问题
- powerbi - 如何在 PowerBI 中获取特定粒度的度量值总数
- java - Java JFileChooser .png 文件到 byte[] 黑色图像
- python - 对矩阵本身求幂N次?