开发者

Dynamic query to immediate execute?

开发者 https://www.devze.com 2022-12-23 05:57 出处:网络
I am using the MSDN Dynamic linq to sql package. It allows using strings for queries. But, the returned type is an IQueryable and not an IQueryable<T>. I do not have the ToList() method.

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

But, the returned type is an IQueryable and not an IQueryable<T>. I do not have the ToList() method.

How can I this immediate execute without manually enumerating over the IQueryable?

My goal is to databind to the Select开发者_运维技巧ing event on a linqtosql datasource and that throws a datacontext disposed exception. I can set the query as the Datasource on a gridview though.

Any help greatly appreciated! Thanks.

The dynamic linq to sql is the one from the samples that comes with visual studio.


The difference between IQueryable and IQueryable<T> is that the second is typed while the first is not. To convert IQueryable into 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 castable into MyType. To select the instances of a certain type you can use the TypeOf<T>() method before doing the cast.

0

精彩评论

暂无评论...
验证码 换一张
取 消