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.

CreateFilteredQuery using multiple contexts

See original GitHub issue
  • Abp package version - 7
  • Base framework - .Net Core.
  • Exception message - The provider for the source 'IQueryable' doesn't implement 'IAsyncQueryProvider'. Only providers that implement 'IAsyncQueryProvider' can be used for Entity Framework asynchronous operations.

Hey Guys,

I cant seem to figure out the solution to this issue. Im using a context per tenant and obviously one for the host. Im also creating a dbset only on the tenants but i need to display it in a list on the host. I have figured out how to achieve this for the most part but i cant seem to figure out how to return a filtered IQueryable for the pagination and sorting/filtering of the list. Seems to me that i cant convert the generic list to an iQueryable and im not sure how to get around that.

For context, i simply want to display a list of licences from all tenants on the host. My actions work already to do what i need with them, this is the only thing i cant get around.

Below is the method im using and above is the error i receive.

Would really appreciate the help if possible.

Cheers for any help in advance, let me know if i can provide anything else to help.

protected override IQueryable<Licence> CreateFilteredQuery(PagedLicenceManagerResultRequestDto input)
        {
            var loggedInUser = _userManager.GetUserById((int)AbpSession.UserId);
            var adminUser = loggedInUser.NormalizedEmailAddress.Contains("SUPPORT");
            var licences = new List<Licence>();
            var tenants = _tenantRepository.GetAllList(t => t.ConnectionString != null && t.ConnectionString != "");
            var builder = new DbContextOptionsBuilder<TenantContext>();
            try
            {
                foreach (Tenant tenant in tenants)
                {
                    TenantContextConfigurer.Configure(builder, SimpleStringCipher.Instance.Decrypt(tenant.ConnectionString));
                    using (var context = new TenantContext(builder.Options))
                    {
                        licences.AddRange(context.Licenses);
                    }
                }
            }
            catch
            {
                return null;
            }
            var query = licences.AsQueryable();
            var test = query.WhereIf(!input.Keyword.IsNullOrWhiteSpace(), x => x.AssignedTo.Contains(input.Keyword) || x.LicenceType.ToString().Contains(input.Keyword));
            return test;
        }

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
pixelapocalypseukcommented, Feb 7, 2022

@ismcagdas thats a good idea, ill impliment that, then it should solve my paging issue aswell! Tyvm!

0reactions
ismcagdascommented, Feb 7, 2022

If that’s the case, you can use Domain Events and create a host side entity (a new entity which is copy of License entity) when a tenant side License entity is created. In that way, a host user can easily query License records.

We are using a similar approach for keeping a list of all users on Host database, see https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Zero.Common/Authorization/Users/UserAccountSynchronizer.cs

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get multiple static contexts in new CONTEXT API ...
One workaround is to use a wrapper that combines the two contexts into one and then export the wrapper. There are multiple ways...
Read more >
Single Context vs Multiple Contexts : r/reactjs
I always lean towards multiple contexts, for data that's not related. When a context is updated, all subscribers re-render. Keeping everything ...
Read more >
How to associate one type with another in multiple contexts?
Another approach decouples messages from the rest of the database, but then I cannot use a CONSTRAINT . A further dilemma: Many Message...
Read more >
React Context & Hooks Tutorial #7 - Creating Multiple ...
Hey gang, in this tutorial I'll show you how to create multiple different contexts for different, un-releated data.
Read more >
React Context & Hooks Tutorial #14
I now know how to apply hooks into my projects. I can't stop watching this series and coding along with you. Great work....
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