Dynamic query for immediate execution?

I am using the MSDN Dynamic linq package for sql. It allows you to use strings for queries.

But the return type is IQueryable , not IQueryable<T> . I do not have a ToList() method.

How can I do this immediate launch without manually listing over IQueryable ?

My goal is to bind data to the Selecting event on the linqtosql data source and which throws an exception other than the datacontext. However, I can set the query as a data source in gridview.

Any help is much appreciated! Thanks.

Dynamic linq to sql is one of the samples that come with visual studio.

+4
source share
1 answer

The difference between IQueryable and IQueryable<T> is that the second is printed and the first is not. To convert IQueryable to IQueryable<T >, you can use the Cast<T>() method.

 IQueryable myQueryable = ...; IQueryable<MyType> myTypedQueryable = myQueryable.Cast<myQueryable>(); IList<MyType> myList = myTypedQueryable.ToList(); 

Obviously, the contents of myQyeryable must be written to MyType . To select instances of a specific type, you can use the TypeOf<T>() method before performing the throw.

+2
source

Source: https://habr.com/ru/post/1303988/


All Articles