Unable to retrieve code. First, automatic migration to work with an existing SQL Server CE database.

Summary:

I will start with a resume, and then follow the details. For my project, automatic migration does not occur in the .sdf database file in the working directory. It is as if the .sdf file did not exist. Instead, all configuration actions are performed in a new, empty database file that it creates in the directory Program Files/Microsoft Visual Studio 10.0/Common7/IDE. How do I get it to work with my .sdf database file in the working directory?

Details:

The project uses Code First EF in Visual Studio 2010 Ultimate. The project was started with EF 4.1, and I just upgraded the project to EF 4.4.

The database file is a SQL Server Compact Edition 4.0 file that is located in the same directory as the executable file (that is, the working directory). For some time, everything has been working fine, but I want to add two new DbSets to the DbContext and, therefore, two new tables to the database file. When I deploy a new version of the program for clients, I want the program to smoothly add two new tables to the database and continue as if nothing had happened, leaving all existing data in other tables intact.

Attempt 1

In the process described at http://msdn.microsoft.com/en-US/data/jj554735 :

DbSets DbContext. , : The model backing the 'DrillContext' context has changed since the database was created. Consider using Code First Migrations to update the database. , , .

:

Enable-Migrations -EnableAutomaticMigrations.

Migrations Configuration.cs.

Update-Database

No pending code-based migrations. , . Program Files/Microsoft Visual Studio 10.0/Common7/IDE, , , , DbSets DbContext- _MigrationHistory, . .sdf , _MigrationHistory.

2, "InitialMigration":

Per http://www.ladislavmrnka.com/2012/03/ef-4-3-migrations-and-existing-database/

, (.. , , ), . 2 DbSets DbContext. Migrations ( Configuration.cs) ( .sdf) ".../Common7/IDE".

:

Enable-Migrations -EnableAutomaticMigrations

Migrations Configurations.cs.

Add-Migration InitialMigration -IgnoreChanges

201208281905525_InitialMigration.cs Migrations.

- Up , InitialMigration :

public partial class InitialMigration : DbMigration
{
    public override void Up()
    {
        Sql("DROP TABLE EdmMetadata");
    }

    public override void Down()
    {
    }
}

Update-Database

The specified table does not exist. , EdmMetadata. .../Common7/IDE , , , .

, "" .../Common7/IDE, .

?

,

+5

All Articles