MySQL Forums
Forum List  »  MySQL for Visual Studio

Re: EF6 Code First with MySQL
Posted by: Gabriel Saliba
Date: November 18, 2014 02:17AM

Hi,

This is just one model which Im trying.

public class Employee
{
[Key]
public int ID { get; set; }

[MaxLength(10)]
public string Name { get; set; }

public string Surname { get; set; }

//I ONLY ADD THIS PROPERTY BETWEEN ONE MIGRATION AND THE OTHER.
public string Address { get; set; }
}
}

This is the configuration class


internal sealed class Configuration : DbMigrationsConfiguration<TestingMYSQLEF6.Data.MyContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator()); CodeGenerator = new MySql.Data.Entity.MySqlMigrationCodeGenerator();
}

protected override void Seed(TestingMYSQLEF6.Data.MyContext context)
{

}

Added that line of code as you suggested.

This is the Context Class


[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class MyContext : DbContext
{
public MyContext()
: base("DefaultConnection")
{

}

public DbSet<Employee> Employees { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}


I followed everything as you suggested but I still get this error.

The issue seems to surface when the database is already created. If I drop the database ax re-run again it works with all migrations first and second but if database is already there the error is prompted in the Package Manager Console


PM> update-database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at MySql.Data.MySqlClient.MySqlConnectionStringBuilder.<.cctor>b__7(MySqlConnectionStringBuilder msb, MySqlConnectionStringOption sender)
at MySql.Data.MySqlClient.MySqlConnectionStringBuilder.get_Item(String keyword)
at MySql.Data.MySqlClient.MySqlConnectionStringBuilder.GetConnectionString(Boolean includePass)
at MySql.Data.MySqlClient.MySqlConnection.get_ConnectionString()
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<GetConnectionString>b__12(DbConnection t, DbConnectionInterceptionContext`1 c)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.GetConnectionString(DbConnection connection, DbInterceptionContext interceptionContext)
at System.Data.Entity.Internal.InternalConnection.GetStoreConnectionString(DbConnection connection)
at System.Data.Entity.Internal.InternalConnection.OnConnectionInitialized()
at System.Data.Entity.Internal.EagerInternalConnection..ctor(DbContext context, DbConnection existingConnection, Boolean connectionOwned)
at System.Data.Entity.DbContext..ctor(DbConnection existingConnection, Boolean contextOwnsConnection)
at System.Data.Entity.Migrations.History.HistoryContext..ctor(DbConnection existingConnection, String defaultSchema)
at MySql.Data.Entity.MySqlEFConfiguration.<.ctor>b__1(DbConnection existingConnection, String defaultSchema)
at System.Data.Entity.Migrations.History.HistoryRepository.CreateContext(DbConnection connection, String schema)
at System.Data.Entity.Migrations.History.HistoryRepository.<GetUpgradeOperations>d__16.MoveNext()
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClassc.<Update>b__b()
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
The given key was not present in the dictionary.

Options: ReplyQuote


Subject
Views
Written By
Posted
3238
November 13, 2014 01:21AM
1399
November 13, 2014 01:36AM
Re: EF6 Code First with MySQL
2193
November 18, 2014 02:17AM
1111
November 26, 2014 07:56AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.