Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 当过滤数据被处理时,如何在域中使用I filter_.net_Xamarin_Realm - Fatal编程技术网

.net 当过滤数据被处理时,如何在域中使用I filter

.net 当过滤数据被处理时,如何在域中使用I filter,.net,xamarin,realm,.net,Xamarin,Realm,我曾在域集合中尝试过如下筛选器IQueryable: public class Configuration { public bool IsFilter { get; set; } public IQueryable<Model> ApplyFilter(IQueryable<Model> collection) { var filterCollection = collection; filterMessage

我曾在域集合中尝试过如下筛选器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;
    }
}
公共类配置
{
公共bool IsFilter{get;set;}
公共可液化ApplyFilter(可液化集合)
{
var filterCollection=集合;
filterMessages=filterMessages.Where(IsFilter | |!IsFilter&&w.IsFilter);
返回过滤器收集;
}
}
当我使用
ApplyFilter
时,我会得到
NotSupportedException


我认为这是因为
配置
的对象已经被处理和收集


如何使用类似的筛选器?

如果您只是试图通过包含的bool属性筛选域模型,则使用Linq Where(
Where(model=>model.IsFilter==IsFilter)

例子:
公共类配置
{
公共bool IsFilter{get;set;}
公共IQueryable ApplyFilter(IQueryable realmQuery)
{
返回realmQuery.Where(model=>model.IsFilter==IsFilter);
}
}
示例用法:
//假设已经创建了“配置”实例:
configuration.IsFilter=true;
realmList.ItemsSource=configuration.ApplyFilter(realmList.ItemsSource作为IQueryable);

请注意,当前,属性必须位于条件的左侧。这意味着

var oldDogs = realm.All<Dog>().Where(dog => 7 < dog.Age); // INVALID query, do not copy
is illegal and would have to be changed into the equivalent

var oldDogs = realm.All<Dog>().Where(dog => dog.Age > 7); // Fixed
var oldDogs=realm.All().Where(dog=>7dog.Age>7);//固定的

谢谢宿醉


但是我认为“领域”应该给出一个描述信息。

是的,但是已经处理和收集的对象
配置中的问题
@Asura为什么要处理该对象?
// Assuming you have an `Configuration` instance already created:
configuration.IsFilter = true;
realmList.ItemsSource = configuration.ApplyFilter(realmList.ItemsSource as IQueryable<ItemModel>);
var oldDogs = realm.All<Dog>().Where(dog => 7 < dog.Age); // INVALID query, do not copy
is illegal and would have to be changed into the equivalent

var oldDogs = realm.All<Dog>().Where(dog => dog.Age > 7); // Fixed