我已经尝试过像这样在领域集合中过滤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
的对象已经被处置和收集了。
如何使用类似的过滤器?
答案 0 :(得分:0)
如果您只是想通过包含的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>);
答案 1 :(得分:-1)
请注意,当前,该属性必须位于条件的左侧。这意味着
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
https://realm.io/docs/dotnet/latest/api/linqsupport.html
感谢@SushiHangover
但是我认为“领域”应该提供描述信息。