开发者

How can I use over by partition in LINQ?

I'm confused about how to change this query to LINQ

  select 
     CONTENT
  from
     (    
        select 
           CONTENT,
           CAM_ID,
           max(CAM_ID) over (partition by DOCUMENT_ID) MAX_ID
        from    
           T_CAM_REVISION
        wh开发者_开发技巧ere 
           DOCUMENT_ID = '101'
     )
  where     
     CAM_ID = MAX_ID

so I can get a single value of content.


There is no way to do max(...) over (...) in LINQ. Here is an equivalent query:

var maxCamID =
    context.T_CAM_REVISION
    .Where(rev => rev.DOCUMENT_ID == "101")
    .Max(rev => rev.CAM_ID);

var query =
    from rev in context.T_CAM_REVISION
    where rev.CAM_ID == maxCamID
    where rev.DOCUMENT_ID == "101"
    select rev.CONTENT;

If you want only a single result:

var result =
    context.T_CAM_REVISION
    .First(rev => rev.CAM_ID == maxCamID
               && rev.DOCUMENT_ID == "101")
    .CONTENT;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜