Random row from Linq to Sql

前端 未结 15 2542
南笙
南笙 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:58

    var cust = (from c in ctx.CUSTOMERs.ToList() select c).OrderBy(x => x.Guid.NewGuid()).Taket(2);
    

    Select random 2 row

提交回复
热议问题