Showing posts with label EF. Show all posts
Showing posts with label EF. Show all posts

Wednesday, January 22, 2014

Database Migrations in Entity Framework Code First

Enabling Migrations

Run the Enable-Migrations command in Package Manager Console

Generating & Running Migrations

Add-Migration migration_name

Update-Database –Verbose

Update-Database –TargetMigration: migration_name

If you want to roll all the way back to an empty database then you can use

Update-Database –TargetMigration: $InitialDatabase

Getting a SQL Script

Update-Database -Script -SourceMigration: $InitialDatabase -TargetMigration: migration_name



Automatically Upgrading on Application Startup (MigrateDatabaseToLatestVersion Initializer)

When we create an instance of this initializer we need to specify the context type (MyDbContext) and the migrations configuration (Configuration) - the migrations configuration is the class that got added to our Migrations folder when we enabled Migrations.

Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyDbContext, Configuration>());



References:
http://msdn.microsoft.com/en-us/data/jj591621.aspx

Saturday, May 19, 2012

Entity Framework 5 Enums and Moving Solution from EF 4.3

  • Moving a solution from EF4.3 +.NET 4 to EF5 +.NET 4.5
  • Using the new SQL Server Object Explorer in Visual Studio 11
  • Working with the new DbLocal database
  • Seeing the enum support in action : how it impacts the database, inserting and querying data with enums.


Original Julie Lerman's post

Friday, February 10, 2012

Выход в свет Entity Framework 4.3 - поддержка миграции

What Changed Between EF 4.2 and EF 4.3

The notable changes between EF 4.2 and EF 4.3 include:

New Code First Migrations Feature. This is the primary new feature in EF 4.3 and allows a database created by Code First to be incrementally changed as your Code First model evolves.

Removal of EdmMetadata table. If you allow Code First to create a database by simply running your application (i.e. without explicitly enabling Migrations) the creation will now take advantage of improvements to database schema generation we have implemented as part of Migrations.

Bug fix for GetDatabaseValues. In earlier releases this method would fail if your entity classes and context were in different namespaces. This issue is now fixed and the classes don’t need to be in the same namespace to use GetDatabaseValues.

Bug fix to support Unicode DbSet names. In earlier releases you would get an exception when running a query against a DbSet that contained some Unicode characters. This issue is now fixed.

Data Annotations on non-public properties. Code First will not include private, protected, or internal properties by default. Even if you manually included these members in your model, using the Fluent API in previous versions of Code First would ignore any Data Annotations on these members. This is now fixed and Code First will process the Data Annotations once the private, protected, or internal properties are manually included in the model.

More configuration file settings. We’ve enabled more Code First related settings to be specified in the App/Web.config file. This gives you the ability to set the default connection factory and database initializers from the config file. You can also specify constructor arguments to be used when constructing these objects. More details are available in the EF 4.3 Configuration File Settings blog post.

читать оригинал