简体   繁体   中英

Lambda Expression casting to Observable Collection

If I have an object of type Person and it has a navigation property of PersonAddressJoin which then has addresses.

PersonResults= new ObservableCollection<Person>(_op.Entities.OfType<Person>());

and I want to then take the PersonAddressJoin navigation property and put that into an object. so i have an ObservableCollection AddressList

AddressList = PersonResults.SelectMany(x => x.PersonAddressJoins);

when i do it this way I get a message that says I cant cast an IEnumberable to an ObservableCollection.?

Can someone help me get that navigation property into this object...thanks

The result of SelectMany is an IEnumerable. Untested, but try:

AddressList = new ObservableCollection<PersonAddressJoins>(PersonResults.SelectMany(x => x.PersonAddressJoins)); 

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