![](/img/trans.png)
[英]Asp.net core webapi entityframework how to query distinct and not in
[英]Translate an postgresql query to entityframework core in asp.net core
我正在尝试使用 entityframework 核心在 dotnet api 应用程序中翻译以下 Postgresql 查询,以返回包含该查询 output 中结果的对象列表。
sql 查询翻译:
select speciality_type, speciality_priority ,
count(speciality_type)
from specialties
group by speciality_priority, speciality_type
所需的 output:
知道最后一列是计数列,女巫最初不在表中,而是我在查询中创建的。 我想从_DataAccessObject.SpecialitiesTable
中获取所有这些列,并从它的值创建另一个我创建object(string type, int priority, int count)
我尝试了很多类似_DataAccess.SpecialitiesTable.GroupBy(...).Select(...)
的东西,一旦调用 function 说 EF 核心语句无法转换为 sql,它们中的大多数都会给我一个错误。
先感谢您。
尝试以下查询:
var result = await _DataAccess.SpecialitiesTable
.GroupBy(s => new { s.speciality_type, s.speciality_priority })
.Select(g => new
{
g.Key.speciality_type,
g.Key.speciality_priority,
count = g.Count()
})
.ToListAsync();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.