如何在LINQ to SQL中将IQueryable转换为Dataset [英] How convert IQueryable to Dataset in LINQ to SQL
本文介绍了如何在LINQ to SQL中将IQueryable转换为Dataset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在3层项目中,我在数据访问层中通过存储过程获取数据,我想将其转换为datatable(用于gridview中的绑定).
服务器端分页不支持IQueryable.
我是这样找到的:
In 3 layers project I get data with store procedure in data access layers and I want convert this to datatable(for bind in gridview).
IQueryable don’t supported from server side paging.
I found this way:
public DataTable GetInfo(int Id)
{
db = new DataClassesDataContext();
DataTable dt=new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("Name");
var query=db.spGetInf(id) .AsQueryable();
var reader = value.GetEnumerator();
while (reader.MoveNext())
{
var rw =reader.Current;
dt.Rows.Add(rw.Id, rw.name);
}
return dt;
}
推荐答案
关于如何从LINQ向ASP.NET网格视图提供向后兼容性的信息很多,特别是有一个看一下这个线程:
http://stackoverflow.com/questions/1595350/why- am-i-not-getting-copytodatatable-in-linq-查询中 [
There''s quite a bit of information on how to provide backwards compatibility to ASP.NET gridviews from LINQ out there, specifically have a look at this thread:
http://stackoverflow.com/questions/1595350/why-am-i-not-getting-copytodatatable-in-linq-query[^]
这篇关于如何在LINQ to SQL中将IQueryable转换为Dataset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文