首页 > 解决方案 > 处理过滤数据时如何在领域中进行过滤

问题描述

我已经尝试在领域集合中过滤 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已经处理和收集的对象。

我如何使用类似的过滤器?

标签: .netxamarinrealm

解决方案


如果您只是试图通过包含的 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>);

推荐阅读