简体   繁体   中英

How do I write a linq query against a ListCollectionView?

none of these seem to do the trick:

var source = myViewModel.MyListCollectionView.Select(x => x as MyType);
var source = myViewModel.MyListCollectionView.Select<object, MyType>(x => x as MyType);
var source = myViewModel.MyListCollectionView.SourceCollection.Select<object, MyType>(x => x as MyType);

ListCollectionView only implements the non-generic IEnumerable interface. I suspect you want:

var source = myViewModel.MyListCollectionView.Cast<MyType>();

or (if some values won't be of MyType , and that's okay):

var source = myViewModel.MyListCollectionView.OfType<MyType>();
var source = myViewModel.MyListCollectionView.OfType<MyType>();

The InternalList property is of type IList so you would be able to write a linq query against that.

ahhhh found it.you have to use Cast<> first!

var source = myViewModel.MyListCollectionView.Cast<MyType>().Select(p=>p.MyProperty);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM