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

Extension not working on DbSet<> methods #18

Open
oo8s opened this issue Feb 23, 2024 · 0 comments
Open

Extension not working on DbSet<> methods #18

oo8s opened this issue Feb 23, 2024 · 0 comments

Comments

@oo8s
Copy link

oo8s commented Feb 23, 2024

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();
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

No branches or pull requests

1 participant