try it
Create a view in SQL server to record a random record
CREATE VIEW RandomView AS SELECT NEWID() As ID
Then create functin on SQL server
CREATE FUNCTION GetNewId ( ) RETURNS uniqueidentifier AS BEGIN RETURN (SELECT ID FROM RandomView) END
then use linq query like this
var qry = from tb in DC.tbcategory where tb.parentID == null order by tb.sortOrder select new { categoryID = tb.CategoryID, ImageID = (from tb in DC.tbImage where tb.CategoryID == tc.CategoryID orderby DC.GetNewId() select tb.ImageID).FirstorDefault() }
I hope this works definitely ....
source share