none
LinqDataSource : How to get top 10 records RRS feed

  • Question

  •  

    how do I change the following query to get just top 10 records? any help

    <
    asp:LinqDataSource ID="LinqDataSource2" runat="server"

     

    AutoPage="false" AutoSort="False"

     

    ContextTypeName="DBLinqSQLDataContext" OrderBy="Population desc"

     

    TableName="Countries" >

     

    </asp:LinqDataSource>

    thx

    Friday, May 29, 2009 10:24 PM

Answers

  • You can select the top 10 in Selecting event. ie:

    MyDataContext db = new MyDataContext();
    e.Result  = db.Countries
               .OrderByDescending(c => c.Population)
               .Take(10)
     
    Saturday, May 30, 2009 12:44 AM