开发者

LINQ execute SQL query with output parameter

开发者 https://www.devze.com 2023-01-15 04:02 出处:网络
I need to execute SQL query with output parameter. For example, SELECT @Count = COUNT(*) FROM dbo.SomeTable

I need to execute SQL query with output parameter.

For example,

 SELECT @Count = COUNT(*) FROM dbo.SomeTable
 开发者_StackOverflow中文版SELECT * FROM SomeTable WHERE Id BETWEEN 1 AND 10

After quering I need to know the @Count value. How can I do it with LINQ without using a stored procedure?

Thank you.


int value = yourDB.SomeTable.Count(q=>q.id >=1 && q.id <= 10);

linq is pretty easy :)


edit: so you want 2 items, the count, and then a limited part of the array.

        List<SomeTable> li = yourDB.SomeTable.ToList();
        int number = li.Count;
        List<SomeTable> partial = li.GetRange(0, 10);

or

        int value = yourDB.SomeTable.Count();
        List<SomeTable> partial = yourDB.SomeTable.ToList().GetRange(0, 10);

so the best LINQ thing for paging is:

        List<SomeTable> partial = yourDB.SomeTable.OrderBy(q=>q.id).Skip(0).Take(10).ToList();
0

精彩评论

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