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

Ability to call Set<T> using an interface type constraint #24451

Closed
mrlife opened this issue Mar 19, 2021 · 1 comment
Closed

Ability to call Set<T> using an interface type constraint #24451

mrlife opened this issue Mar 19, 2021 · 1 comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@mrlife
Copy link

mrlife commented Mar 19, 2021

The following code requires a class:

public virtual DbSet<TEntity> Set<TEntity>()
where TEntity : class

Possible to call Set<T>() with an interface?

public string GetValue<T>(int id) where T : IMyInterface
{
    return context.Set<T>().Where(t => t.Id == id).FirstOrDefault(v => v.Value);
}
@ajcvickers
Copy link
Member

@mrlife No. Entity types must be concrete; see #757 which is about mapping interfaces to entity types.

@ajcvickers ajcvickers added customer-reported closed-no-further-action The issue is closed and no further action is planned. labels Mar 19, 2021
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

2 participants