[英]ef core 5 Group By items in list
Hi I want to group a list by items inside an array嗨,我想按数组中的项目对列表进行分组
var localitiesList = localities.Where(x => x.Level == 1).Select(x=>x.Name);
var doctorsGoupedByLocalities = docs.GroupBy(x => localitiesList).Select(doctor => new {
LocalityName = doctor.Key,
doctors = _mapperService.Map<IEnumerable<Doctor>, IEnumerable<DoctorDto>>(doctor.Select(x => x))
});
the result by doing it this way这样做的结果
{
"localityName": [
"item 1",
"item2"
],
"doctors": [..]
}
but what I need as a response is something like this但我需要的回应是这样的
{[{
"localityName": [
"item 1"
],
"doctors": [..]
}, {
"localityName": [
"item 2"
],
"doctors": [..]
}]
How can I get a response like that by grouping from items inside an array.我如何通过对数组中的项目进行分组来获得这样的响应。
Any help is much appreciated.任何帮助深表感谢。 Thank you.
谢谢你。
you are grouping by a list base on another list, this is not proper way.您正在根据另一个列表按列表分组,这不是正确的方法。 you have to group by docs by a property of their own, if you haven't such property you have to create new relation between doctors and localities
你必须按医生自己的财产分组,如果你没有这样的财产,你必须在医生和地方之间建立新的关系
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.