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

Prevent DbContext.Set<T>() from creating sets for types not in the model #4301

Closed
rowanmiller opened this issue Jan 13, 2016 · 2 comments
Closed
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@rowanmiller
Copy link
Contributor

Currently we create sets for any type... but they fail ungracefully if used to do anything (NullReferenceException etc.). We should just throw in the Set method if T is not in the model.

@ajcvickers
Copy link
Member

@rowanmiller Note that the fix for this will throw when the Set method is called with an unmapped type, but will not prevent the application from putting DbSet properties of unmapped types in their context. I expect these will still null ref in some way. Is this okay?

If we decide to also do a check for DbSet properties in the context, the check cannot happen at construction time since this would require model initialization which would kill perf for creating unused context instances. So the check would need to be done when the set is used, or for all DbSet properties at the time of full context initialization.

@rowanmiller
Copy link
Contributor Author

@ajcvickers yeah I think that is fine... putting a DbSet, then ignoring the type, then trying to use the DbSet is probably not very common 😄

@ajcvickers ajcvickers modified the milestones: 1.0.0-rc2, 1.0.0 Oct 15, 2022
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

3 participants