Database creation problem (EF6.1.3, dotConnector for MySql 8.3.379)

Database creation problem (EF6.1.3, dotConnector for MySql 8.3.379)

Postby kim10987 » Mon 30 Mar 2015 14:31

Hello devart team,

I am trying to switch Oracle's MySQL Connector/Net to Devart's.
And, I have a problem with database creation.

Do I must create a database instance before I use?

I got the following error when there is no such "DevartTest2" database in the db server.
InnerExcpetion: {"Unknown database 'DevartTest2'"}
(When I use Oracle's MySQL Connector/Net, it automatically creates DB)

Is there a way(option) to create database automatically?

Here is the code I tested.
//--------------------

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;

namespace dotConnectForMySqlTest
{
public class Student
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int StudentID { get; set; }
public string StudentName { get; set; }
public DateTime? DateOfBirth { get; set; }
public byte[] Photo { get; set; }
public decimal Height { get; set; }
public float Weight { get; set; }
}

public class SchoolContext : DbContext
{
public SchoolContext()
{
Database.SetInitializer(new CreateDatabaseIfNotExists<SchoolContext>());
}

public DbSet<Student> Students { get; set; }
}

class Program
{
static void Main(string[] args)
{
using (var ctx = new SchoolContext())
{
Student stud = new Student() { StudentName = "New Student" };
ctx.Students.Add(stud); // Error!!
ctx.SaveChanges();
}
}
}
}
//----------

Thank you in advance
kim10987
 
Posts: 7
Joined: Mon 30 Mar 2015 14:14

Re: Database creation problem (EF6.1.3, dotConnector for MySql 8.3.379)

Postby Shalex » Mon 30 Mar 2015 15:20

Please try these lines before running the code which should create a database:
Code: Select all
var config = Devart.Data.MySql.Entity.Configuration.MySqlEntityProviderConfig.Instance;
config.DatabaseScript.Schema.DeleteDatabaseBehaviour = Devart.Data.MySql.Entity.Configuration.DeleteDatabaseBehaviour.Database;

For more information, refer to http://www.devart.com/dotconnect/mysql/docs/?DBScripGeneration.html.
Shalex
Devart Team
 
Posts: 7610
Joined: Thu 14 Aug 2008 12:44

Re: Database creation problem (EF6.1.3, dotConnector for MySql 8.3.379)

Postby kim10987 » Mon 30 Mar 2015 15:31

Thank you so much! It works now as I expected :-)
kim10987
 
Posts: 7
Joined: Mon 30 Mar 2015 14:14


Return to dotConnect for MySQL