使用select max list将sql转换为linq

时间:2018-03-23 03:49:04

标签: c# sql linq

请帮帮我。如何将其转换为Linq

select * from t_collect_op_dtl_kimper co 
where co.PTDHCARD_ID ='489144'
and kimper_id = (select max(kimper_id) from t_collect_op_dtl_kimper 
co1 where co.PTDHCARD_ID = co1.ptdhcard_id and co.model =co1.model)

2 个答案:

答案 0 :(得分:0)

以下代码对您有所帮助,

var result = t_collect_op_dtl_kimper
             .Where( x => x.PTDHCARD_ID == 489144 && 
                     x.kimper_id == t_collect_op_dtl_kimper
                     .Where( y => y.PTDHCARD_ID == x.PTDHCARD_ID && y.model == x.model ) 
                     .Max( y => y.kimper_id ) )
             .ToList();

答案 1 :(得分:0)

如果您更喜欢查询理解,您可以直接翻译SQL:

viewRender: function(view, element) {
  // add handler to watch items inserted into .fc-view to catch popovers and re-init tooltips
  $('.fc-view').on('DOMNodeInserted', function (e) {
    if ($(e.target).hasClass('fc-popover')) {
      $('[data-toggle="tooltip"]').tooltip({ container: 'body', html: true }); // re-init tooltips
    }
  });
},