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
Describe what this method does? #2288
Comments
@bzaar Please provide some more details on what you are trying to use this method for. It is typically used internally to build the target model for the model-diffing part of Migrations. |
I am not using it directly. The method was generated using My main question is why does the generated method duplicate the whole database schema on every migration? I would only expect to see the diff there. My database schema is quite large so I was surprised to see it duplicated in every migration. Or am I doing something wrong here? |
I don't understand what you mean by this. This method creates an EF model. It doesn't directly do anything to the database schema. |
Sorry for not making myself clear. Maybe I should step back a bit. I'm setting up EF Core 3.1.3 migrations against an existing SQL Server database. This is what I've done so far:
Then I added a property to an entity class and ran Now looking at the BuildTargetModel method of the second migration I see that it contains pretty much the same code as MyDbContextModelSnapshot.BuildModel. I.e. it lists all entities and all their properties and relationships. This seems strange to me as I would only expect to see the differences in migration code. Is it by design that the whole schema, including tables that have not changed, is duplicated in every migration's BuildTargetModel()? |
Migration.BuildTargetModel stores the model which will be created as a result of that particular migration. ModelSnapshot will have same content as last migration's target model. It helps dotnet ef in the case snapshot file is removed. |
@bzaar Yes. |
OK thanks for taking the time to clear up my doubts. |
Just out of curiosity, under what scenario might BuildTargetModel() for a non-final and non-initial migration be called? |
@bzaar It is used to provide supplemental information for some operations, like the column types for InsertDataOperation |
@AndriySvyryd @ajcvickers from my view I see it's too much code, could I empty this method after migrations has been applied ? |
@levanlongktmt If you are not planning to reapply the migrations the recommended approach is to squash them. Currently you'd need to do this manually, but we are working on making this easier. |
And why does the generated method duplicate the whole database schema on every migration?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: