How to show first five records in Entity Framework

Total Post:26

Points:182
 802  View(s)
Ratings:
Rate this:
Hi All,

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

How to show first five records in Entity Framework
I want to find first 5 records. Please can anyone help.
Thank you.
  1. Post:135

    Points:949
    Re: How to show first five records in Entity Framework

    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 Apr-11-2018 03:18:17 AM

Answer