LINQ Using Max() to select a single row

前端 未结 6 1432
轻奢々
轻奢々 2020-12-02 16:13

I\'m using LINQ on an IQueryable returned from NHibernate and I need to select the row with the maximum value(s) in a couple of fields.

I\'ve simplified the bit tha

6条回答
  •  無奈伤痛
    2020-12-02 17:06

    More one example:

    Follow:

     qryAux = (from q in qryAux where
                q.OrdSeq == (from pp in Sessao.Query() where pp.FieldPk
                == q.FieldPk select pp.OrdSeq).Max() select q);
    

    Equals:

     select t.*   from nametable t  where t.OrdSeq =
            (select max(t2.OrdSeq) from nametable t2 where t2.FieldPk= t.FieldPk)
    

提交回复
热议问题