Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Way to reduce compiled DLL bloat when using Entity Framework Code First Migrations

We have been using EF with Code First Migrations for a while, and our DLL has grown to almost 10 megabytes. This may not seem like a big deal, but every time we add a migration to our project, it's causing the DLL to grow.

I've found that excluding the migrations from the project file works okay, and doesn't harm anything (as long as your databases already have those migrations). Is that an acceptable way of handling the bloat, or is there some reason they need to stick around? Or is there an alternative way of keeping the files there in the project but not letting them bloat things so much?

like image 538
Nicholas Head Avatar asked Oct 24 '13 20:10

Nicholas Head


People also ask

How do you use migration in code first approach?

Step 1 − Before running the application you need to enable migration. Step 2 − Open Package Manager Console from Tools → NuGet Package Manger → Package Manger Console. Step 3 − Migration is already enabled, now add migration in your application by executing the following command.

How do I disable Code First migrations?

You need to go to Management Studio, open your database tables, go to System Tables folder and remove __MigrationHistory table that is located there (for EF6 and above, it's located directly under Tables ). This will disable Migrations for good.

How does migration work in Entity Framework?

EF Core compares the current model against a snapshot of the old model to determine the differences, and generates migration source files; the files can be tracked in your project's source control like any other source file. Once a new migration has been generated, it can be applied to a database in various ways.


1 Answers

No, you don't have to include the project with migrations into your deploy package. No "real" project should reference that one. But you do need it for Update-Database.

(Originally answered in comment.)

like image 130
Ilia Barahovsky Avatar answered Nov 15 '22 10:11

Ilia Barahovsky