-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Improve logging around context model caching #11608
Comments
note that there seems to be some static "type to mapping" caching going on. since if u split the data context into a base and two implementations (https://github.com/SimonCropp/EfViewMappingRepro/tree/inheritanceWorkaround) it seems to work as expected |
@SimonCropp Yes, the model is cached based on a cache key that by default includes the context type, so having a different context type for each model is a good way to handle this. You could instead configure a different cache key--see https://docs.microsoft.com/en-us/ef/core/modeling/dynamic-model for details. |
@ajcvickers thanks for the prompt reply |
@ajcvickers given this is very difficult to debug. wouldnt it be better to detect and log that there are conflicting context both loaded into the static context? |
Re-purposing this issue to improve the logging for this, as suggested by @SimonCropp. |
Thanks @ajcvickers |
So when mapping a view there is a workaround that can be taken.
This can be done by passing a bool into the custom
DbContext
, so the same context can be used from the installation context and the usage contextHowever when instantiating two different instances of said context, one with
mapViews: false
and one withmapViews: true
, the entity mapping from the first context seems to be re-used in the second context.This results in a
InvalidOperationException : Cannot create a DbSet for 'MyView' because this type is not included in the model for the context.
note that, after the first run to create the db, if you comment out the following
The usage of the view will work
full repro: https://github.com/SimonCropp/EfViewMappingRepro
Targeting SQL Server 2016 on windows 2012R2
repro'd with the following nuget combos
also verified on both netcoreapp2 and net461
The text was updated successfully, but these errors were encountered: