Dim query = From o In myContainer.MyObjects Select o.MyStringProperty Distinct
Dim myProperties As List(Of String) = query.ToList????? 'no way!!!'
"query" type is IEnumerable(Of String)
I tried to use the query
directly as a DataSource of a (infragistic) combobox, but it throws me NullReferenceException, so I decided to convert it to a listof strings, to be a more "classical" datasource.
Dim values As List(Of String) = query.AsQueryable().ToList()
does not work either: Value of type 'System.Collections.Generic.List(Of System.Linq.IQueryable(Of String))' cannot be converted to 'System.Collections.Generic.List(Of String)'.
Your error message suggests the query
is actually a List(Of T)
containing a collection internally.
If this is the case, you can use SelectMany
to flatten the collection:
Dim values As List(Of String) = query.SelectMany(Function(m) m).ToList()
Edit: Given your edit, as well as the comment, the following should work fine:
Dim values As List(Of String) = query.ToList()
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