开发者

Query that gets only the records needed to the page using LINQ

开发者 https://www.devze.com 2023-01-08 15:43 出处:网络
I want to use LINQ\'s IQueryable th开发者_Go百科at gives me the query that gets only the records needed to the page based on the page size I have given.

I want to use LINQ's IQueryable th开发者_Go百科at gives me the query that gets only the records needed to the page based on the page size I have given.

I have used this:

System.Linq.IQueryable<DataTable> ds = 
    (from m in dttableDetails.TableName select m).Take(page_size).Skip(offset);

but it is showing me an error. I need the returned type as Datatable/Dataset. How to do this? Please help. The error is:

Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<char>' to 'System.Linq.IQueryable<System.Data.DataTable>'. An explicit conversion exists (are you missing a cast?)


dttableDetails.TableName returns the name of the table, so from m in dttableDetails.TableName select m returns an enumerable which iterates over the characters in the string, hence you get an IEnumerable<char>

Try

var results = (from m in dttableDetails select m).Take(page_size)


This might help c-sharp corner

0

精彩评论

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