view raw
Subalfa Subalfa - 6 months ago 62
C# Question

ASP.NET MVC5 doesn't create MySQL database except break at the initializer

I'm a beginner in ASP.NET MVC5. Using the following tutorial:

I'm using the following code:

public class MyDBContext : DbContext
public MyDBContext()
: base("MyDBContextConnectionString")
Database.SetInitializer<MyDBContext>(new MyDBInitializer());

public DbSet<User> Users{get;set;}
public DbSet<History> Histories{get;set;}
public DbSet<Place> Places{get;set;}
public DbSet<Review> Reviews{get;set;}
public DbSet<Type> Types{get;set;}

protected override void OnModelCreating(DbModelBuilder modelBuilder)

The web.config:

<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/>

<add name="MyDBContextConnectionString" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;UserId=root;Password=******;database=KorulottemDB;CharSet=utf8;Persist Security Info=True" />
<remove name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />

Unfortunately doesn't create the database except I break at the initializer:

Database.SetInitializer<MyDBContext>(new MyDBInitializer());

and click on the "The function evaluation requires all threads to run".

enter image description here

The database appears on the server in this case but without tables.

Thanks for all help.


Since you're using Code First approach, i recommend you to use Migrations too. To enabel that you can run the following command in Package Manager Console:

Enable-Migration -ProjectName <YourDataLayer>

You should try to use Package Manager Console, in Visual Studio, and run the following command:

Update-Database -ProjectName <YourDataLayer>