Totally confused about the data types required here.
I have this Linq statement:
var feat = AllCustomers
.Select(c => c.CustomerServices.SelectMany(cs => cs.CustomerServiceFeatures)
.SelectMany(csf => csf.ConfigElements).Where(ce => ce.Name == "ItemType").Select(ce => ce.Value).Distinct());
It returns the required data, and VS tells me that the type is being set as:
System.Data.Objects.ObjectQuery<System.Collections.Generic.IEnumerable<string>>
However I want to add this data into a list of strings:
List<string> itemTypes = new List<string>();
itemTypes.AddRange(feat);
But this throws an error:
Argument 1: cannot convert from 'System.Linq.IQueryable<System.Collections.Generic.IEnumerable<string>>' to 'System.Collections.Generic.IEnumerable<string>'
I can't find the required syntax to cast to correct type. Can anyone help?
Cheers, Matt
Compile-time error shows, that feat
is "collection of collection of string" (literally "IQueryable of IEnumerable of string"). So you need to generate flat collection.
feat.SelectMany(x => x)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With