如何将sql查询转换为linq? [英] How do I convert sql query to linq?

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

问题描述



我有一个查询,它返回其注册日期最小的员工ID。如何在Linq中编写此查询?这适用于SQL。非常感谢帮助。



从tsample中选择empid,其中date =(从tsample中选择MIN(日期),其中WaitLstInd ='Y'和eventid = 757)

Hi,
I have a query which returns the employee id whose date of registration is minimum of all. How do I write this query in Linq? This works in SQL. Help is much appreciated.

select empid from tsample where date = ( select MIN(date) from tsample where WaitLstInd='Y' and eventid=757)

推荐答案

DateTime mindate = objtsalmple.Where(k => k.WaitlstInd == "Y" && k.eventid == 757).Select(k => k.date).Min();
            var temp = objtsalmple.Where(k => k.date == mindate).FirstOrDefault();
            if (temp != null)
            {
                int empid = temp.empid;
            }


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

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