如何从sql查询中编写Linq查询或lambda表达式 [英] how to write Linq query or lambda expresion from sql query
本文介绍了如何从sql查询中编写Linq查询或lambda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
i想写这个SQL查询的linq查询或lambda expresion
选择跨度>最大(tblEmailList.name),计数(tblEmailRecipientList.ListId)<跨度类= 代码关键字 >从跨度> tblEmailList <跨度类= 代码关键字>加入跨度> tblEmailRecipientList <跨度类= 代码关键字>上跨度> tblEmailRecipientList.ListId = tblEmailList.ListId
<跨度类= 代码关键字>基跨度> <跨度类=代码 - 关键字> by tblEmailRecipientList.ListId
提前感谢
解决方案
尝试如下:
var result = 来自 p context.tblEmailRecipientList
join c in context.tblEmailList等于c.ListId
group p by p.ListId into temp
select new
{
TotalCount = temp.Count(),
MaxName = temp.Max(m = > m.name)
};
从这里开始:如何:执行分组连接(C#编程指南) [ ^ ]
请你在卡住时回到这里。
详情请见:
查询表达式语法示例:加入运算符 [ ^ ]
查询表达式语法示例:分组 [ ^ ]
如何:用C#编写LINQ查询 [ ^ ]
101 LINQ样本 [ ^ ]
LINQ查询表达式( C#编程指南) [ ^
Hi All,
i want to write linq query or lambda expresion fot this sql query
select Max(tblEmailList.name),count(tblEmailRecipientList.ListId) from tblEmailList join tblEmailRecipientList on tblEmailRecipientList.ListId = tblEmailList.ListId
group by tblEmailRecipientList.ListId
thanks in advance
解决方案
Try like below:
var result = from p in context.tblEmailRecipientList join c in context.tblEmailList on p.ListId equals c.ListId group p by p.ListId into temp select new { TotalCount = temp.Count(), MaxName = temp.Max(m => m.name) };
Start here: How to: Perform Grouped Joins (C# Programming Guide)[^]
Please, come back here when you get stuck.
For further details, please see:
Query Expression Syntax Examples: Join Operators[^]
Query Expression Syntax Examples: Grouping[^]
How to: Write LINQ Queries in C#[^]
101 LINQ Samples[^]
LINQ Query Expressions (C# Programming Guide)[^]
这篇关于如何从sql查询中编写Linq查询或lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文