Entity Framework 6 does not create tables
Posted by: dfg sdfghf
Date: February 20, 2014 02:46PM

Hi,

My Entity Framework 6 does not create tables. Is there a way that it creates tables if they don't exist?

MySQL 5.5.28
EF6
EF MySQL Connector 6.8.3

Here is my code. Creating a table manually works fine, but on SaveChanges an exception is thrown with "Table 'db257952_1349.Artikels' doesn't exist"

using (var dbContext = new ArtikelContext())
{
// This statement works and create a table in the database
dbContext.Database.ExecuteSqlCommand("Create Table Test3(id int)", new object[0]);

Artikel artikel = new Artikel { Barcode = "12345" };
dbContext.Artikel.Add(artikel);

dbContext.SaveChanges();
}

This is my Context and the Configuration that sets the MySQLSQLGenerator

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class ArtikelContext : DbContext
{
public ArtikelContext()
: base("NMHomeDB")
{
}

public DbSet<Artikel> Artikel { get; set; }
public DbSet<Kategorie> Kategorien { get; set; }
}

internal sealed class Configuration : DbMigrationsConfiguration<ArtikelContext>
{
public Configuration()
{
SetSqlGenerator("MySql.Data.MySqlClient.EF6", new MySqlMigrationSqlGenerator());
}
}

Btw. The connection is established over SSH Tunnel, but i think this unimportant.

Thank you
Nic
(I tried to change my name, but it wasnt working... :-|)

Options: ReplyQuote


Subject
Written By
Posted
Entity Framework 6 does not create tables
February 20, 2014 02:46PM


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.