Display Top 5 and Last 5 Record from a user Entity using Linq using C#
User Table:
=========
Create Table User (
Id int Identity(1,1) Primary Key,
Name Nvarchar(100) null
);
insert into User values("Sreenivas")("Sreenivasulu");
IN SQL Server script:
================
Select Top 5 * from Users order by Name -- Top 5
Select Top 5 * from Users order by Name desc -- Last 5
In LINQ Query:
============
_Context.Users.OrderBy(a=>a.Name).Take(5); -- Top 5
_Context.Users.OrderByDecending(a=>a.Name).Take(5); -- Last 5
Comments
Post a Comment