Here is simple EF based program that worked wonderfully with MS SQL server:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySQLTest;
namespace initDB
{
class Program
{
static void Main(string[] args)
{
try
{
using (var context = new Entities())
{
Console.WriteLine("Creating mote descriptors");
{
var mote1 = new moteDescriptor();
mote1.ID = "mote1";
mote1.dnsName = "mote1.cloudapp.net";
mote1.moteRefreshSecs = 20;
mote1.Active = "N";
mote1.publicPort = 2399;
mote1.lanPort = 2499;
mote1.lanAddress = "10.0.0.4";
mote1.refreshTime = DateTime.Now;
context.moteDescriptors.Add(mote1);
}
{
var mote2 = new moteDescriptor();
mote2.ID = "mote2";
mote2.dnsName = "mote2.cloudapp.net";
mote2.moteRefreshSecs = 20;
mote2.Active = "N";
mote2.publicPort = 2399;
mote2.lanPort = 2499;
mote2.lanAddress = "10.0.0.5";
mote2.refreshTime = DateTime.Now;
context.moteDescriptors.Add(mote2);
}
context.SaveChanges();
Console.WriteLine("Creating mote descriptors successful");
Console.WriteLine("Success!!!");
}
}
catch (Exception ex)
{
String exceptionString = "";
for (Exception ex1 = ex; ex1 != null; ex1 = ex1.InnerException)
{
exceptionString = exceptionString + ex1.Message;
}
Console.WriteLine("Exception: {0}", ex);
}
}
}
}
With MySQL it doesn't work. The exception is thrown:
Creating mote descriptors
Exception: System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.Entity.Core.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException:
You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '(SELECT
`moteDescriptors`.`ID`,
`moteDescriptors`.`dnsName`,
`moteDescriptors`' at line 1
в MySql.Data.MySqlClient.MySqlStream.ReadPacket() в d:\Projects\odesk\fruitman\code\mysql-connector-net-6.9.6-src\Source\MySql.Data\MySqlStream.cs:строка 163
в MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
The SQL statement must be generated by MySQL entityframework provider. It seems to be incorrect.
So, the question: can I use the Entity Framework with MySQL or not?
The EF connector is 6.9.6. The EntityFramework is 6.0, but I tried with 5.0 with the same result.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySQLTest;
namespace initDB
{
class Program
{
static void Main(string[] args)
{
try
{
using (var context = new Entities())
{
Console.WriteLine("Creating mote descriptors");
{
var mote1 = new moteDescriptor();
mote1.ID = "mote1";
mote1.dnsName = "mote1.cloudapp.net";
mote1.moteRefreshSecs = 20;
mote1.Active = "N";
mote1.publicPort = 2399;
mote1.lanPort = 2499;
mote1.lanAddress = "10.0.0.4";
mote1.refreshTime = DateTime.Now;
context.moteDescriptors.Add(mote1);
}
{
var mote2 = new moteDescriptor();
mote2.ID = "mote2";
mote2.dnsName = "mote2.cloudapp.net";
mote2.moteRefreshSecs = 20;
mote2.Active = "N";
mote2.publicPort = 2399;
mote2.lanPort = 2499;
mote2.lanAddress = "10.0.0.5";
mote2.refreshTime = DateTime.Now;
context.moteDescriptors.Add(mote2);
}
context.SaveChanges();
Console.WriteLine("Creating mote descriptors successful");
Console.WriteLine("Success!!!");
}
}
catch (Exception ex)
{
String exceptionString = "";
for (Exception ex1 = ex; ex1 != null; ex1 = ex1.InnerException)
{
exceptionString = exceptionString + ex1.Message;
}
Console.WriteLine("Exception: {0}", ex);
}
}
}
}
With MySQL it doesn't work. The exception is thrown:
Creating mote descriptors
Exception: System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.Entity.Core.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException:
You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '(SELECT
`moteDescriptors`.`ID`,
`moteDescriptors`.`dnsName`,
`moteDescriptors`' at line 1
в MySql.Data.MySqlClient.MySqlStream.ReadPacket() в d:\Projects\odesk\fruitman\code\mysql-connector-net-6.9.6-src\Source\MySql.Data\MySqlStream.cs:строка 163
в MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
The SQL statement must be generated by MySQL entityframework provider. It seems to be incorrect.
So, the question: can I use the Entity Framework with MySQL or not?
The EF connector is 6.9.6. The EntityFramework is 6.0, but I tried with 5.0 with the same result.