如何使用c#将sql查询转换为linq? [英] How to convert sql query to linq using c#?

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

问题描述

请朋友帮我转发下面的SQL查询到linq。



选择b.DISTRICT,b.TEHSIL,b.UID,b.BeneficiaryFullname,b .BeneficiaryRationCardID,b.Gender

来自



选择BeneficiaryRationCardID,min(DOB)为MaxAge

来自BPLFamilyDetails其中gender ='F'

group by BeneficiaryRationCardID

)a

内部联接BPLFamilyDetails b on a.BeneficiaryRationCardID = b.BeneficiaryRationCardID and a .MaxAge = b.DOB

内部加入



选择x.BeneficiaryRationCardID

来自BPLFamilyDetails x

左连接(从BPLFamilyDetails中选择BeneficiaryRationCardID,其中UID为空)y on x.BeneficiaryRationCardID = y.BeneficiaryRationCardID

其中y.BeneficiaryRationCardID为null

group by x.BeneficiaryRationCardID

)c on a.BeneficiaryRationCardID = c.BeneficiaryRationCardID

其中b.Gender ='F'



我尝试了什么:



我试过在线工具将查询从sql转换为linq但没有成功。

请帮我解决这个问题。

Please any buddy help me to convert below sql query to linq.

Select b.DISTRICT,b.TEHSIL,b.UID,b.BeneficiaryFullname,b.BeneficiaryRationCardID, b.Gender
from
(
select BeneficiaryRationCardID, min(DOB) as MaxAge
from BPLFamilyDetails where gender='F'
group by BeneficiaryRationCardID
) a
inner join BPLFamilyDetails b on a.BeneficiaryRationCardID=b.BeneficiaryRationCardID and a.MaxAge=b.DOB
inner join
(
select x.BeneficiaryRationCardID
from BPLFamilyDetails x
left join (select BeneficiaryRationCardID from BPLFamilyDetails where UID is null) y on x.BeneficiaryRationCardID=y.BeneficiaryRationCardID
where y.BeneficiaryRationCardID iS null
group by x.BeneficiaryRationCardID
) c on a.BeneficiaryRationCardID=c.BeneficiaryRationCardID
where b.Gender='F'

What I have tried:

I have tried for online tool to convert query from sql to linq but didnt succeed.
please help me to get out of this.

推荐答案

Linqer是一个SQL to LINQ转换工具。它有助于学习LINQ并将原始SQL语句转换为LINQ。 Linqer支持.NET语言 - C#和Visual Basic。按照以下链接下载该工具:



Linqer [ ^ ]
Linqer is a SQL to LINQ converter tool. It helps to learn LINQ and convert raw SQL statements to LINQ. Linqer supports both .NET languages - C# and Visual Basic. Follow below link to download the tool:

Linqer[^]


试试这个linq 101



C#中的101个LINQ样本 [ ^ ]
Try this linq 101

101 LINQ Samples in C#[^]


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

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