Random row from Linq to Sql

前端 未结 15 2559
南笙
南笙 2020-11-22 05:39

What is the best (and fastest) way to retrieve a random row using Linq to SQL when I have a condition, e.g. some field must be true?

15条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 05:55

    Came here wondering how to get a few random pages from a small number of them, so each user gets some different random 3 pages.

    This is my final solution, working querying with LINQ against a list of pages in Sharepoint 2010. It's in Visual Basic, sorry :p

    Dim Aleatorio As New Random()
    
    Dim Paginas = From a As SPListItem In Sitio.RootWeb.Lists("Páginas") Order By Aleatorio.Next Take 3
    

    Probably should get some profiling before querying a great number of results, but it's perfect for my purpose

提交回复
热议问题