如何在Lambda表达式中转换Sql server Query [英] How to convert Sql server Query in Lambda expression
本文介绍了如何在Lambda表达式中转换Sql server Query的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SELECT [t0].[Id],
[t0].[Challan_No],
[t0].[Type],
[t0].[Measurement],
[t0].[Update_By],
[t0].[Date],
[t1].[Id] AS [Id2],
[t1].[Challan_No] AS [Challan_No2],
[t1].[Own_Comany],
[t1].[Parti_Name],
[t1].[Update_By] AS [Update_By2],
[t1].[Date] AS [Date2],
[t1].[IsDelete],
[t1].[Isgenbill],
[t2].[Rate] AS [Rate1]
FROM [dbo].[Challan_Total] AS [t0]
INNER JOIN [dbo].[Challan] AS [t1] ON [t0].[Challan_No] = [t1].[Challan_No]
INNER JOIN [dbo].[Rate] AS [t2] ON [t0].[Type] = [t2].[Meterial_type]
AND [t1].Own_Comany = [t2].Company_Id
AND [t1].Parti_Name=[t2].Parti_Id
WHERE [t0].[Challan_No] = '2014CH 10002'
我试过:
I tried:
var getch = dm.Challan_Totals
.Join(dm.Challans,
c => c.Challan_No, d => d.Challan_No,
(c, d) => new { c, d }).Select(b => b)
.Join(dm.Rates,
r => r.c.Type, s => s.Meterial_type &&
q => q.c., sq => sq.Meterial_type,
(r, s) => new { r, s.Rate1 })
.Where(m => m.r.c.Challan_No == "2014CH 10002");
推荐答案
您可以使用Linq2Sql的DataContext.GetCommand
You may use Linq2Sql'sDataContext.GetCommand
DbCommand dc = db.GetCommand(TheQeury);
查看关于方法的msdn文章 [ ^ ]
[已添加]
或
请参阅 linqpad [ ^ ](正如Eliyahu在上面的帖子中所建议的,我我不确定轻量级免费版包含的是什么......)
[\ added]
干杯,>
C
Check out the msdn article on the method[^]
[added]
OR
See linqpad[^] (as suggested by Eliyahu in the thread above, I am not sure what the "lightweight" free version includes though...)
[\added]
Cheers,
C
var result = dm.Challan_Totals
.Join(dm.Challans,
ct => ct.Challan_No,
c => c.Challan_No,
(ct, c) => new { ct, c })
.Join(dm.Rates,
ctc => new
{
Type = ctc.ct.Type,
Own_Company = ctc.c.Own_Comany,
Parti_Name = ctc.c.Parti_Name
},
rt => new
{
Type = rt.Meterial_type,
Own_Company = rt.Company_Id,
Parti_Name = rt.Parti_Id
},
(ctc, rt) => new { ctc, rt })
.Where(x => x.ctc.ct.Challan_No == "2014CH 10002")
.Select(res => new
{
Challan_no = res.ctc.ct.Challan_No,
Type = res.ctc.ct.Type,
Measurment = res.ctc.ct.Measurement,
Rate1 = res.rt.Rate1,
Amount = (res.ctc.ct.Measurement) * ((double)res.rt.Rate1)
})
.ToList();
这篇关于如何在Lambda表达式中转换Sql server Query的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文