score:15
Accepted answer
You can use the Take() method
List<aspnet_News> allNews = context.aspnet_News.OrderByDescending(i => i.NewsId)
.Take(3) // Takes the first 3 items
.ToList();
It'll also handle the case where the list contains less than 3 items and take them only.
score:2
Use method Take() and if you need, you can use Skip() as well.
Source: stackoverflow.com
Related Query
- How can select first 3 item of list<>
- How to select first list item to null using Linq
- How can I get the index of an item in a list in a single step?
- How can a LINQ join select only the first record?
- In C#, how can i determine if a list has any item from another list?
- When using Linq's GROUP BY to create a list of groups, how can I select a specific group by its key?
- How do I select everything in a list after the first occurence of?
- How to select objects from a list that has a property that matches an item in another list?
- How can I select using LINQ for an entry that contains a LIST with more than one row?
- How can I select a category and the first picture associated with that category?
- In EF Core, how can I perform a group by and select a list of comma separated values?
- How can i copy data table records of different field name based on mapping list evaluating condition on source data table?
- Using ASP.NET and MVC 3, how can I create hidden fields so that a List with an array as a value of each item in the list binds correctly?
- Using Linq lambdas, how can I get the first item in a two-key-sorted list?
- How to select multiple item from list with related condition
- How to loop through a child list of objects in Entity Framework 4.1 code first
- How to select Item from an property list using Expression Tree in c#
- how to select data by linq in many-to-many relationship in First code Entity framework 5
- How do i filter list of A objects based on each object's first item
- how i can get the item Of subGroup list Through the group List
- How can I select from an included entity in LINQ and get a flat list similar to a SQL Join would give?
- How can I use LINQ to select a property and also other items of a list at the same level?
- How can I search a list of objects that contains a list of objects for the first entry that contains an element matching my search criteria?
- How can I select distinct and ordered data into a generic list from multiple lists?
- LINQ: how to zip 2 lists and select elements where first list is distinct?
- How can I find the first items in a list with a different value for a property using Linq?
- How can I select the first child of a child using linq?
- How to select an entity from database based on nested list item match?
- Entity Framework Code First Select Item Based on Relationship
- how can I Select One row where max StartDate in list objects using linq
More Query from same tag
- Which is fast : Query Syntax vs. Loops
- Using Linq foreach how to call a function with two arguments
- Keep HTML tags in XML using LINQ to XML
- Count embedded documents mongodb c# LINQ
- Error Trying to pass a IEnumerable list with Linq and Mvc Web API
- ASP.NET working with DB-forms using LINQ
- Property on model class could not be set to null
- Find duplicates within multiple lists using linq
- How can I distinct with condition?
- How to pull a SQL Server table into memory in order to run queries against it
- Linq to SQL to return multiple counts from query not returning correct results
- how to run multiple LINQ queries on the same datafile
- LINQ group by with an aggregate function (method syntax)
- Function predicate to string
- How To Introduce a Void Method to a LINQ Query with Query Syntax
- Traverse a xml tree recursively and push element value into custom class
- How to populate a Class with Dictionary using LINQ 3
- Conflict on EntityState.Modified because two objects of same model Class?
- Find difference between two Data Objects using LINQ
- Get the rows where column/field sum equals a certain value
- Orderby() not ordering numbers correctly c#
- Linq to XML Converter
- Parametrized List<K>.Cast<T> with parametrized initialization
- LINQ and Entity Framework - Avoiding subqueries
- c# linq join three list to nested dictionary
- Specified cast is invalid error, LINQ to Oracle table
- Best Approach SQL Server Calculated Column vs In Code Approach
- Getting a Linq-toSQL query to show up on a GridView
- Problem in DataGridView binding with LINQ?
- LINQ Query that is able to identity a Row in a Junction Table with two variables - How to do it?