Retrieve records from database randomly in LINQ

Answered Retrieve records from database randomly in LINQ

  • Wednesday, August 08, 2007 4:58 AM
     
     

    Is there a way to get a specific amount of record from a table  randomly? like we always did in SQL
    SELECT TOP 10 * FROM TABLE1 ORDER BY NEWID();
    I tried to use order by Guid.Newid() but it didn't work

    "orderby" is only one step in a LINQ expression building series, like:

    Code Snippet

    var aaa = from c in ctx.ccc

                     select c;

    swtich(circumstance1)

    {

    //add some filter

    }

     

    swtich(circumstance2)

    {

    //add some filter

    }

     

    swtich(ordertype)

    {

    //different order types including order by newid()

    }

     

     

    if I use ctx.ExecuteQuery, I nearly need to re-write all the codes in SQL statement is there anything like SqlMethod I can use?

All Replies