Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1451

Entity Framework 6 does not create tables (no replies)

$
0
0
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... :-|)

Viewing all articles
Browse latest Browse all 1451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>