How can we get random entities by using DO? In TSQL we can do:

SELECT TOP 2 * FROM Table ORDER BY NEWID()

But Query.All<myentity>().OrderBy(ent => Guid.NewGuid()).FirstOrDefault() doesn't work - can't translate to SQL.

Is there a best way to do this?

asked Mar 21 '12 at 14:11

Ness's gravatar image

Ness
155232328


One Answer:

Try to use a custom LINQ compiler like this: http://support.x-tensive.com/question/4812/getutcdate

answered Mar 21 '12 at 21:53

ara's gravatar image

ara
395858791

1

Thanks, we'll try to use this approach.

(Mar 22 '12 at 04:23) Ness Ness's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×1

Asked: Mar 21 '12 at 14:11

Seen: 1,506 times

Last updated: Mar 22 '12 at 04:23

Related questions

powered by OSQA