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.OfTy开发者_如何学Cpe<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));
精彩评论