Home > DeveloperSection > Forums > How to show first five records in Entity Framework
Sachin Singh
Sachin Singh

Total Post:26

Posted on    March-22-2016 12:36 AM

 ASP.NET MVC C#  ASP.Net  ASP.NET MVC  Entity Framework 

 1 Reply(s)
 531  View(s)
Rate this:
Hi All,

I want to display first five records using entity frameworks using ASP.NET MVC.
My code  is below :

I want to find first 5 records. Please can anyone help.
Thank you.

Anupam Mishra

Total Post:135

Posted on    March-22-2016 12:44 AM

Hi Sachin

This is a very basic approach to finding:

 var screens = db.AssignedScreen.Take(5).ToList();
we have also IEnumerable Interface we have also use like this:
 var screens= db.AssignedScreen.ToList().Take(5);  
or, we have also sort our element

 var screens =  db.AssignedScreen.OrderByDescending(c => c.arg**).Take(5).ToList();
** arg is a argument

Modified On Mar-22-2016 12:44:55 AM

Don't want to miss updates? Please click the below button!

Follow MindStick