question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to merge IQueryable for AsyncCrudAppService GetAll

See original GitHub issue

Hi, 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:closed
  • Created 6 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
acjhcommented, Jan 14, 2020

I know this is irrelevant but there is no such a thing

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.

How can I include GrandChildList? Since it is not like EfCore in which we can use Include and ThenInclude

So add a reference to EF Core.

return Repository.GetAll().Include(x => x.ChildList).ThenInclude(t => t.GrandchildList);
1reaction
acjhcommented, Feb 19, 2018
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found