问题
We have a database schema with ~200 tables. Model snapshot (Migration.Designer.cs) which is created for each migration is ~20K lines. So, having quite a number of migrations really slows down our build on CI (with ~30 migrations building a solution takes 6 minutes with migrations or 4 minutes without them).
So, to the question: is it safe to delete model snapshots for old migrations (that we know we will never Revert)? Are model snapshots used for anything else except Revert-Migration?
回答1:
Are model snapshots used for anything else except Revert-Migration?
Yes. There are a few edge cases where it's needed. On SQL Server, those cases are:
- AlterColumn when the column is narrowed or the computed expression is changed and the indexes need to be rebuilt
- CreateIndex on a memory-optimized table when the index is unique and references nullable columns
So most of the time it's probably safe to delete, but please test that your migrations still work after doing so.
回答2:
Got the same problem on my current project. Above 400 migraitons and 6m lines of code inside .Designer. Here is how I managed to resolve this problem:
MigrationProject.csproj
<PropertyGroup>
...
<DefaultItemExcludes Condition="'$(Configuration)' == 'Debug' ">$(DefaultItemExcludes);Migrations\**\*.Designer.cs</DefaultItemExcludes>
</PropertyGroup>
This way you dont need to reset migration neither delete .Designer files.
来源:https://stackoverflow.com/questions/47048721/entity-framework-core-is-it-safe-to-delete-migration-designer-cs-if-we-will-nev