Reputation: 509
I am working on these lists to get an item that matches the selected item from the combobox.
private void InitializaMessageElement()
{
if (_selectedTransactionWsName != null)
{
get a transaction webservice name matching the selected item from the drop down here the output=TestWS which is correct
var getTranTypeWsName = TransactionTypeVModel
.GetAllTransactionTypes()
.FirstOrDefault(transTypes =>
transTypes.WsMethodName == _selectedTransactionWsName);
Loop the list of wsnames from the treenode list. Here it gives me all the node I have which is correct.
var wsNameList = MessageElementVModel
.GetAllTreeNodes().Select(ame =>
ame.Children).ToList();//. == getTranTypeWsName.WsMethodName);
find the getTranTypeWsName.WsMethodName in the wsNameList. Here is where I have the problem:
var msgElementList = wsNameList.Select(x => x.Where(ame => getTranTypeWsName != null && ame.Name == getTranTypeWsName.WsMethodName)).ToList();
my MsgElement list:
_msgElementObsList = new ObservableCollection<MessageElementViewModel>(msgElementList);
this.messageElements = _msgElementList;
NotifyPropertyChanged("MessageElements");
}
Here it is throwing exception Cannot convert from 'System.Collections.Generic.IEnumerable<System.Collections.Generic.IEnumerable to System.Collections.Generic.List).
Upvotes: 1
Views: 187
Reputation: 3668
You have a List of IEnumerable not a List of MessageElementViewModel. That is why you are throwing an error.
Not sure which one you need but you could fix your Select function like this.
var msgElementList = wsNameList.Select(x => x.Where(ame => getTranTypeWsName != null && ame.Name == getTranTypeWsName.WsMethodName).First()).ToList();
or
var msgElementList = wsNameList.SelectMany(x => x.Where(ame => getTranTypeWsName != null && ame.Name == getTranTypeWsName.WsMethodName)).ToList();
Upvotes: 1
Reputation: 3289
Can you rework your msgElementList
to
var msgElementList = wsNameList.Where(x => x.Name == getTranTypeWsName.WsMethodName).ToList();?
The getTranTypeWsName != null
doesn't belong in there I don't think because it doesn't compare with any of the lambda's members.
Upvotes: 0