Unable to merge IQueryable for AsyncCrudAppService GetAll
See original GitHub issueHi, I have simple Product AsyncCrudAppService and I’m trying to override GetAll method to exclude duplicates based on property ProductGroupId
so I get only one product per group in the result, but I also need to include all products that are not in any group (NULL). I’ve tried things like Concat/Union
but these result in strange errors (key cannot be null, AnonymousObject etc).
public override async Task<PagedResultDto<ProductDto>> GetAll(PagedAndSortedResultRequestDto input)
{
CheckGetAllPermission();
var query = CreateFilteredQuery(input);
// 1. One product per group
query = query.Where(x => x.ProductGroupId != null).GroupBy(x => x.ProductGroupId).Select(x => x.First());
// 2. Products not belonging to any group
query = query.Where(x => x.ProductGroupId == null);
var totalCount = await AsyncQueryableExecuter.CountAsync(query);
query = ApplySorting(query, input);
query = ApplyPaging(query, input);
var entities = await AsyncQueryableExecuter.ToListAsync(query);
return new PagedResultDto<ProductDto>(
totalCount,
entities.Select(MapToEntityDto).ToList()
);
}
Queries 1 & 2 work well if the other one is commented, but i need to have them both applied so any help with merging them is appreciated.
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Unable to combine two IQueryAbles
So, to solve the problem, you have to make both the objects of the same type. Either create a hardcoded type for both...
Read more >Merging two iqueryables that are projected to one entity ...
I'm mapping from two different but similar Entity Framework Entities (EXAMEN and EXPLORACION) to my domain entity Estudio, with the following ...
Read more >Lee's Blog - RSSing.com
this IQueryable existingQuery, IMainFilterDto filter) ... Ever made it to production only to realize your code fails miserably ... GetAll .
Read more >How To Push Updates to Raspberry Pi UWP Apps in Prod
Then you have to remember to update again when you merge to master, and possibly again for release branches. The problem is that...
Read more >Asp.NET Core+ABP框架+IdentityServer4+MySQL+Ext JS ...
登录完成后,我们继续来完成余下的功能。本文要完成的是文章管理功能,主要包括后台应用层服务以及客户端存储(Store)的数据访问调整。
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Regardless of whether there is, you shouldn’t post irrelevant comments on closed issues. Especially when there are other issues that are directly relevant and already answered.
So add a reference to EF Core.
Related issue: https://github.com/aspnet/EntityFrameworkCore/issues/11007