linq select a random row

后端 未结 6 1426
悲&欢浪女
悲&欢浪女 2020-12-30 03:05

I have a table called Quotes in linq-to-sql that contains 2 columns: author and quote. How do you select both columns of a random row?

6条回答
  •  抹茶落季
    2020-12-30 03:40

    1 First create a class with rend property

    public class tbl_EmpJobDetailsEntity
    {
        public int JpId { get; set; }
        public int rend
       {
        get
          {
            Random rnd = new Random();
            return rnd.Next(1, 100);
          }
        }
    }
    

    2 Linq query

    var rendomise = (from v in db.tbl_EmpJobDetails
    select new tbl_EmpJobDetailsEntity
    {
       JpId=v.JpId
    }).OrderBy(o=>o.rend);
    

提交回复
热议问题