-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add a lightweight version of DbContext #19610
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Would this be a user-facing thing, or more of an internal building block for compiled models? |
This is user-facing, they will need to place the model building code in a different assembly (along with migrations) than this runtime context to be able to avoid loading model building code in production. |
OK, thanks for the explanation. It would be nice to do a design session once where you give an overview of what you're planning :) |
Sure, but I don't think that the benefits of doing this will ever be enough to justify the cost of implementation. |
@AndriySvyryd Do you mean you created an issue that you think we will close? The question of how to create the compiled model and consume it at runtime has been bothering me for five years! This does seem like it could be a way forward. |
Yes, as a pragmatic optimist while I don't think we'll do this I hope we will. |
@ajcvickers I'm sure you guys already thought about it, but what about starting with a serializable implementation of the IModel and generate that one via a command line at CI time, and configure the context to load this serialized model in the startup.cs. |
@ilmax Yes, we've thought about it 😄 : #1906 (comment), #8258, #12511 |
This is no longer necessary due to how trimming works. |
One without
OnConfiguring
andOnModelCreating
methods. These can be optionally specified inAddDbContext
.Optimized for use with compiled model and context pooling. It will allow using EF without loading any model building types.
OnModelBuilding
can be moved to options:DbContextOptionsBuilder.OnModelBuilding(Action<ModelBuilder> buildModel)
Consider doing something similar for
DatabaseFacade
if migration code is not trimmed out even whenEnsureCreated
/EnsureDeleted
is not used.Limitations:
Alternatively, we can define a feature switch for model building to allow the code to be trimmed.
The text was updated successfully, but these errors were encountered: