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
Database creation problem (EF6.1.3, dotConnector for MySql 8.3.379)
Re: Database creation problem (EF6.1.3, dotConnector for MySql 8.3.379)
Please try these lines before running the code which should create a database:
For more information, refer to http://www.devart.com/dotconnect/mysql/ ... ation.html.
Code: Select all
var config = Devart.Data.MySql.Entity.Configuration.MySqlEntityProviderConfig.Instance;
config.DatabaseScript.Schema.DeleteDatabaseBehaviour = Devart.Data.MySql.Entity.Configuration.DeleteDatabaseBehaviour.Database;
Re: Database creation problem (EF6.1.3, dotConnector for MySql 8.3.379)
Thank you so much! It works now as I expected