gpt4 book ai didi

SQL 到 Entity Framework 计数分组

转载 作者:行者123 更新时间:2023-12-03 05:17:56 25 4
gpt4 key购买 nike

我需要将此 SQL 语句转换为 Linq-Entity 查询...

SELECT name, count(name) FROM people
GROUP by name

最佳答案

查询语法

var query = from p in context.People
group p by p.name into g
select new
{
name = g.Key,
count = g.Count()
};

方法语法

var query = context.People
.GroupBy(p => p.name)
.Select(g => new { name = g.Key, count = g.Count() });

关于SQL 到 Entity Framework 计数分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11564311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com