Skip to content

FindDbContexts(): use ServiceType instead of ImplementationType #119

@hjrb

Description

@hjrb

Hi
this works for me:
if (!service.ServiceType.IsSubclassOf(typeof(DbContext))) continue; if (discoveredServices.Any(x => x.DbContextType == service.ServiceType)) continue; foreach (var dbSetProperty in service.ServiceType.GetProperties()) { // looking for DbSet<Entity> if (dbSetProperty.PropertyType.IsGenericType && dbSetProperty.PropertyType.Name.StartsWith("DbSet")) { if (!options.IgnoreEntityTypes.Contains(dbSetProperty.PropertyType.GenericTypeArguments.First())) { discoveredServices.Add(new DiscoveredDbSetEntityType() { DbContextType = service.ServiceType, DbSetType = dbSetProperty.PropertyType, UnderlyingType = dbSetProperty.PropertyType.GenericTypeArguments.First(), Name = dbSetProperty.Name }); } } }
I'm not using Code First but DB First and Aspire. ImplementationType is null as Factory is being used. Don't know if that has implications elsewhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions