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();
精彩评论