Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Duplicated tables #10

Closed
devantler opened this issue Aug 9, 2021 · 3 comments · Fixed by #11
Closed

Bug: Duplicated tables #10

devantler opened this issue Aug 9, 2021 · 3 comments · Fixed by #11

Comments

@devantler
Copy link
Contributor

devantler commented Aug 9, 2021

When I set this admin panel up with a DbContext that extends ApiAuthorizationDbContext<ApplicationUser> to authenticate with IdentityServer, I get duplicated DbSets.

image

Is there a way to ensure it does not list DbSet's if they are already listed? Or filter DbSets, to only show e.g. Users and Roles as well as my custom DbSets such as Ecosystems.

EDIT:
I think the duplicated DbSets are caused by this code when a user inherits from a subtype of DbContext:

private static void FindDbContexts(IServiceCollection services)
{
    foreach (var service in services.ToList())
    {
        if (service.ImplementationType == null)
            continue;
        if (service.ImplementationType.IsSubclassOf(typeof(DbContext)))
        {
            services.AddTransient(services => new DiscoveredDbContextType() { Type = service.ImplementationType });
        }
    }
}

I suspect the services collection contains multiple references to the implemented DbContext so it can be resolved from all its inherited interfaces. As such, I believe a DiscoveredDbContextis added for each found subtype of DbContext even though they reference the same implemented DbContext. Maybe a check can be made to check whether a DbContext has already been processed, and in that case, it can be skipped, so the DbSets are no longer duplicated.

I hope this helps! :-)

@edandersen
Copy link
Owner

Thanks so much for spotting this. Maybe an overload for AddCoreAdmin() that takes a type of DbContext to constrain it could work?

@devantler
Copy link
Contributor Author

Yeah, this would definitely work, but a way to support not adding multiple dbContexts by default, would be nice.

Do you mind me making a PR for this, when i have the time?

@edandersen
Copy link
Owner

Absolutely I accept PRs!

@devantler devantler changed the title Duplicated DbSets from ApiAuthorizationDbContext, and feature proposal to filter shown DbSets Duplicated DbSets Aug 26, 2021
@devantler devantler changed the title Duplicated DbSets Bug: Duplicated tables Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants