I need to filter a ObservableCollection with a(Where(x=>x.IsMallExternal == false))
.
using this code:
ObservableCollection<Shop> test = allShopsForCat.Where(x => x.IsMallExternal == false);
I get this error:
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<DataModel.Shop>' to 'System.Collections.ObjectModel.ObservableCollection<DataModel.Shop>'.
So I am using this code as a solution instead, but seems not the best way.
- I would like to know how to filter ObservableCollection with
.Where
in my method.
public ObservableCollection<Shop> Shops
{
get
{
ObservableCollection<Shop> allShopsForCat = App._dataSource.GetShopsForCategoryAll(_id);
//ObservableCollection<Shop> test = allShopsForCat.Where(x => x.IsMallExternal == false); // THIS DOES NOT WORK
ObservableCollection<Shop> shopsNotExternal = new ObservableCollection<Shop>();
// Get only shops for category which are internal to mall
foreach (var shop in allShopsForCat)
{
if (shop.IsMallExternal == false)
{
shopsNotExternal.Add(shop);
}
}
return shopsNotExternal;
}
}