109221793 109221793 - 1 month ago 10
C# Question

LINQ query to select top five

I have a LINQ query:

var list = from t in ctn.Items
where t.DeliverySelection == true && t.Delivery.SentForDelivery == null
orderby t.Delivery.SubmissionDate
select t;


How can I modify this query to select just five results from the database?

Answer
var list = (from t in ctn.Items
           where t.DeliverySelection == true && t.Delivery.SentForDelivery == null
           orderby t.Delivery.SubmissionDate
           select t).Take(5);
Comments