LINQ query to select top five

后端 未结 6 1201
轻奢々
轻奢々 2020-12-02 05:46

I have a LINQ query:

var list = from t in ctn.Items
           where t.DeliverySelection == true && t.Delivery.SentForDelivery == null
           ord         


        
6条回答
  •  臣服心动
    2020-12-02 06:20

    [Offering a somewhat more descriptive answer than the answer provided by @Ajni.]

    This can also be achieved using LINQ fluent syntax:

    var list = ctn.Items
        .Where(t=> t.DeliverySelection == true && t.Delivery.SentForDelivery == null)
        .OrderBy(t => t.Delivery.SubmissionDate)
        .Take(5);
    

    Note that each method (Where, OrderBy, Take) that appears in this LINQ statement takes a lambda expression as an argument. Also note that the documentation for Enumerable.Take begins with:

    Returns a specified number of contiguous elements from the start of a sequence.

提交回复
热议问题