Skip to content

Extension not working on DbSet<> methods #18

@oo8s

Description

@oo8s

Hi

The extension methods seems to work only for properties of type DbSet but not on any methods having similar signature
Error message:

QueryableValues only works on a DbContext with at least one public DbSet<> or IDbSet<>.

As per source code

Usage exemple:

var codes = this.dbContext.AsQueryableValues(searchParameter.MyCodes);
this.dbContext.Set<MyEntity>().AsQueryable().Where(e => codes.Contains(e.Code)));

Could the extension work with EF6 methods returning DbSet<> as well ?
Or any advise ?

Something like this in DbSetByDbContextFactory

var entityType = this.dbContext.GetType()
                    .GetMethods()
                    .Select(i => i.ReturnParameter.ParameterType)
                    .Where(i => i.IsGenericType && isDbSet(i.GetGenericTypeDefinition()))
                    .Select(i => i.GenericTypeArguments[0])
                    .FirstOrDefault();

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