如何在linq中转换此查询 [英] How to convert in linq this query

查看:110
本文介绍了如何在linq中转换此查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在linq中转换此查询:



从[dbo]中选择t.Message

。[tblA] t

内连接(

选择消息,最大值(CreatedDate)为MaxDate

来自[dbo]。[tblA]

group by Message

)tm on t.Message = tm.Message and t.CreatedDate = tm.MaxDate

其中Type ='Enter'



我尝试了什么:



i需要在linq中转换此SQL查询

解决方案

像这样:

  var  result1 = context。 tbla 
。其中(m => m.Type == 输入
.GroupBy(m => m.Message)
。选择(grp => grp.OrderByDescending(m => m.CreateDate).First(m => m.Message));


how to convert in linq this query :

select t.Message
from [dbo].[tblA] t
inner join (
select Message, max(CreatedDate) as MaxDate
from [dbo].[tblA]
group by Message
) tm on t.Message = tm.Message and t.CreatedDate = tm.MaxDate
where Type='Enter'

What I have tried:

i need to convert this sql query in linq

解决方案

Like this:

var result1 = context.tbla
        .Where(m=>m.Type=="Enter") 
        .GroupBy(m=>m.Message)
        .Select(grp=>grp.OrderByDescending(m=>m.CreateDate).First(m=>m.Message)); 


这篇关于如何在linq中转换此查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆