Print Page | Close Window

Code First Migration

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3611
Printed Date: 13-May-2026 at 1:03am


Topic: Code First Migration
Posted By: Vonzkie
Subject: Code First Migration
Date Posted: 06-Sep-2012 at 12:20am
Hi,

Do you have a working example of a Devforce Code First project that uses the Migration Feature of Entity Framework 4.3?
Cause I'm having hard time trying to do what is instructed on this article:
http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx - http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx

I have some errors while executing NuGet commands and I don't know if this is not compatible with Devforce.

Thanks,
Von



Replies:
Posted By: Vonzkie
Date Posted: 06-Sep-2012 at 1:12am
Btw., I have an existing database here, I do not create my Database using code first.

Here are my errors:

PM> Enable-Migrations -Force
No classes deriving from DbContext found in the current project.
Edit the generated Configuration class to specify the context to enable migrations for.
No migrations configuration type was found in the assembly ' MyDomain'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).


PM> Add-Migration Sample -StartupProjectName "MyDomain"
No migrations configuration type was found in the assembly 'MyDomain'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).

Note: I have a custom DBContext in my project


Posted By: Walid
Date Posted: 06-Sep-2012 at 3:27am
Hi,

In the console, you might need to specify in the Default Project combo the Assembly where you DBContext is located.


Posted By: Vonzkie
Date Posted: 06-Sep-2012 at 5:26pm
Hi,

Actually, that's what I did, I select the Project where the DBContext resides.

Btw., the error shown above happened when I used 4.3.1 version of EF4.
Now, I use 4.3.0 and the error didn't show but this is the new error:

PM> Enable-Migrations -Force
System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Configure(EdmEntityType entityType, EdmModel model)
   at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntities(EdmModel model)
   at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
   at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
   at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
   at System.Data.Entity.Migrations.Extensions.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w)
   at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(Action`1 writeXml)
   at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(DbContext context)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
   at System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Object reference not set to an instance of an object.

PM> Add-Migration Sample -StartupProjectName "iRely.Model"
System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Configure(EdmEntityType entityType, EdmModel model)
   at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntities(EdmModel model)
   at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
   at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
   at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
   at System.Data.Entity.Migrations.Extensions.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w)
   at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(Action`1 writeXml)
   at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(DbContext context)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
   at System.Data.Entity.Migrations.Design.ToolingFacade.GetPendingMigrationsRunner.RunCore()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Object reference not set to an instance of an object.






Posted By: Vonzkie
Date Posted: 06-Sep-2012 at 6:26pm
This is the link of my project:
uploads/1228/iRely.Model.rar - uploads/1228/iRely.Model.rar

The Database Backup is inside the folder Backup


Posted By: Vonzkie
Date Posted: 10-Sep-2012 at 6:36pm
Hi Guys,

Just want to follow up this.. 

Thanks,
Von


Posted By: sbelini
Date Posted: 11-Sep-2012 at 9:14am
Hi Von,
 
I'm still investigating and will keep you posted.
 
Silvio.


Posted By: sbelini
Date Posted: 11-Sep-2012 at 1:53pm
Hi Von,
 
I isolated the issue to the [ForeignKey].
I'm still working on determining if this is an EF or DevForce issue.
In the meantime, in order to get you going, you should remove all [ForeignKey] tags from your code.
Note that for your code in particular most of them are redundant because the PK~FK is following naming convention, but you still have a few relations you should either change the property names to follow convention or use fluent API.
 
I'm attaching your sample with the changes I made, so you can get a headstart: uploads/892/iRely.Model.zip - uploads/892/iRely.Model.zip
 
Regards,
   Silvio.


Posted By: Vonzkie
Date Posted: 12-Sep-2012 at 4:20am
Hi,

Ok thanks..
Just keep me posted on how it goes.
Btw, did you already encountered some errors like the following:

1st Error:

Error 7 An error occurred during metadata generation and a metadata file could not be created.  Error: Unable to find the requested .Net Framework Data Provider.  It may not be installed. iRely.TankManagement.Model

2nd Error:

Error 7 An error occurred during metadata generation and a metadata file could not be created.  Error: Sequence contains more than one element iRely.TankManagement.Model

This happens when I compile the model (This is not the same model as the first one I send)





Posted By: sbelini
Date Posted: 12-Sep-2012 at 9:03am
Von,
While I was able to compile and enable Migrations in the sample I sent you, it's just for your reference.
I moved the Entity classes around to keep them organized.
Basically the change is that I removed the ForeignKey tags and added a few necessage navigation using fluent API.
Also, be sure to update the connectionString.
Silvio.


Posted By: Vonzkie
Date Posted: 12-Sep-2012 at 6:57pm
Hi Silvio,

What I mean to say is the Model I'm compiling now with those errors is not the same as the one i send or the one you send, this are separate set of tables, basically another model.

Thanks,
Von


Posted By: Vonzkie
Date Posted: 12-Sep-2012 at 8:13pm
Hi Silvio,

Disregard my last reply, I already fixed the issue.
But with the orignial post, just update me when you're done.

Thanks,
Von



Print Page | Close Window