Click here to Skip to main content
15,905,612 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

Dear sir,


My SQL Server Query is here...

select * From restaurant where Country='India' and city='Chennai' order by  displayby asc  ,newid()



anyone know How convert into LINQ format.


reply me....

Note:

While Converting these Query Error Occured like, newid() not supported in LINQ.
Posted
Updated 4-Jun-12 20:51pm
v2

1 solution

I think the Guid.NewGuid().ToString() as explained here Guid.NewGuid Method[^] may be used instead of newid() in the LINQ query
 
Share this answer
 
v2
Comments
Mohankumar.Engain 5-Jun-12 2:56am    
Hey VJ Reddy, I am generating Random records so i use NewID() in SQL same as LINQ Query Random.next().
What is use of Guid.NewGuid.ToString().
Not working ur method. reply me
VJ Reddy 5-Jun-12 3:33am    
Guid.NewGuid().ToString() generates a globally unique ID which can be thought of a Random combination of alpha numeric characters.
For eg. the following code
for(int i=0; i<10; i++)
Console.WriteLine (Guid.NewGuid().ToString());

generates the following output.

//a5d1f707-8e9b-491f-abd3-4ba755bb5c9d
//4331afda-e252-41ce-bb4a-f713bca8e1f2
//3b3cb54e-b355-489a-8491-0ada71d26e24
//cf13a56e-3c70-4ded-9641-fce5aaabbd3b
//88da0998-abb2-41f1-a2dd-5f7d425912d3
//f6ce53e8-b8af-4ae6-902c-e737d6cce29b
//d1d4406d-9030-40cc-816a-503783200392
//49bce8df-2807-4315-84b9-94da3b53555b
//3b2c9144-e973-496d-b4da-e16f63684c1a
//bf97ad06-6c32-420c-addf-7ce19d04b20f

The NEWID explained here http://msdn.microsoft.com/en-us/library/ms190348.aspx generates an ID like
6F9619FF-8B86-D011-B42D-00C04FC964FF

So Guid.NewGuid().ToString() can be used to generate a Random ID in C# and can be used in LINQ like NEWID used in Sql Server
Mohankumar.Engain 6-Jun-12 5:34am    
In my above Query:
DisplayBy=1,2,3,4,5,6,7,8,9,...(Four Time Repeated this value in table)

Your query is worked when select the records(Shuffled Totally All records).
But I need Shuffled with grouping, like based on DisplayBy field.
within DisplayBy field shuffled together each...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900