SQL Lead and Lag functions from C# code

前端 未结 2 1751
栀梦
栀梦 2021-01-14 01:02

Is it possible to use the LEAD or LAG SQL functions from C#?

My preference of method is:

  1. Linq to SQL
  2. Entity Framewor
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-14 01:57

    Awesome lib linq2db https://github.com/linq2db/linq2db supports Window-Functions with LEAD and LAG:

        from p in db.Parent
        join c in db.Child on p.ParentID equals c.ParentID
        select new
        {
            Diff = Sql.Ext
                      .Lag(x.time, Sql.Nulls.None)
                      .Over()
                      .PartitionBy(p.time.Date)
                      .OrderBy(p.time)
                      .ToValue()
        };
    

提交回复
热议问题