- Do until phosphorescence: Create Simple MVC 3 App with VWDExpress and MariaDB without table creation
- Create the initializer class
using System;
DropCreateDatabaseAlways is the one of superclasses we can select. Others are DropCreateDatabaseIfModelChanges and CreateDatabaseIfNotExists.
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace Mvc3Training.Models
{
public class Mvc3TrainingInitializer : DropCreateDatabaseAlways<Mvc3TrainingContext>
{
}
} - Add mantra to Mvc3TrainingContext
using System.Data.Entity.ModelConfiguration.Conventions;
So, that's the limit. We must abandon the convention for pluralizing table names. MySQL Connector/Net still has such a bug. If not, MySQL Connector/Net creates the table with singularized name and looks up the table with pluralized name.
namespace Mvc3Training.Models
{
public class Mvc3TrainingContext : DbContext
{
........
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
........
}
} - Add this code to Application_Start method in Global.aspx.cs
Database.SetInitializer<Mvc3TrainingContext>(new Mvc3TrainingInitializer());
- Launch the server, than access to the controller you maked.
Wednesday, July 6, 2011
Updated MySQL Connector/Net
Labels:
ASP.NET MVC,
MariaDB
Current MySQL Connector/Net is 6.3.7, and this version can do code first in limited condition. This post expresses the instruction of code first with MariaDB.
No comments:
Post a Comment