Mirricle

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



Re: LINQ Project General Retrieve records from database randomly in LINQ


Re: LINQ Project General Retrieve records from database randomly in LINQ

Joe Albahari

I'm curious as to whether a solution exists for the original question, i.e.:

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();


My first thought was to to write a SQL function... but then you get an error when trying to use NEWID() in the function!

Joe