Getting Linq to play with Mysql and Mono, is this possible?

I am trying to get Linq to work with Mysql on Ubuntu using the Mono version in the repositories (2.10.5), and I only get headaches.

First of all, I had to change the MySQL provider sqlmetal.exe.config, because by default the old and outdated version was installed for it, I was able to get it to work with installing the MySQL connector that I installed on this computer (from the repositories) in as a supplier for sqlmetal. I created a DataContext with sqlmetal for my target database, and it seemed to work, but I'm not quite sure.

After creating the DataContext, I created a new project for monodevelop just to test this, first I tried to use a simple MysqlConenction and check that the connector is working correctly, I had to add the connector assembly to the project, but it worked fine, it worked. Then I tried to connect using a DataContext using this code:

    using System;
    using System.Linq;
    using System.Data.Linq;
    using MySql.Data.MySqlClient;

    namespace test
    {
            public class test
        {
            public static void Main (String[] args)
            {           
                Test db = new Test (new MySqlConnection("Userid=root;database=test;server=localhost;password=password"));

                foreach(var tr in db.Users)
                {
                    Console.Write(tr.Username);
                }
            }
        }
    }

This code does not work. Linq seems to be generating bad SQL for MySQL, at least the exception that it throws seems like:

Unhandled Exception: 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 '[Id], [Password], [Username]
FROM [test].[Users]' at line 1
  at MySql.Data.MySqlClient.MySqlStream.ReadPacket () [0x00000] in <filename unknown>:0 
  at MySql.Data.MySqlClient.NativeDriver.GetResult (System.Int32& affectedRow, System.Int32& insertedId) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: 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 '[Id], [Password], [Username]
FROM [test].[Users]' at line 1
  at MySql.Data.MySqlClient.MySqlStream.ReadPacket () [0x00000] in <filename unknown>:0 
  at MySql.Data.MySqlClient.NativeDriver.GetResult (System.Int32& affectedRow, System.Int32& insertedId) [0x00000] in <filename unknown>:0 

Does anyone know if it is possible to connect to MySQL using Linq and Mono? Is something missing?

Thank!

+5
source share
1 answer

, , , , LINQ to SQL Mono.
: LINQ to SQL Mono MySQL ( PostgreSQL).

: DbLinqProvider . SQL-, MySQL.

SQL SQL Server:

"FROM [test].[Users]"

"FROM `test`.`Users`"

"DbLinqProvider = MySql" . .
.: http://www.mono-project.com/Release_Notes_Mono_2.6#LINQ_to_SQL

, Mono/DbLinq - (, ), .

+5

All Articles