Page 1 of 1

InvalidCastException - "Devart.Data.Linq.DataQuery to Sys...

Posted: Sun 06 Sep 2009 15:13
by Falke
Hi,

I am using LINQ.i created the datacontext object and i want to have a list back from the query. By doing that like:


Dim a as List(Of context.user) = From c in db.user Select c Order By c.Name Descending

i got an error:

InvalidCastException - "Devart.Data.Linq.DataQuery to Type System.Collections.Generic.List

How can i solve it?

Posted: Mon 07 Sep 2009 14:49
by Shalex
Your expression can be cast to IList by calling the System.Linq.Enumerable.ToList method. Please pay attention to types of the left and right sides of assigning to make the right cast in the future. For more information, please refer to the LINQ documentation in MSDN.