sqlkata / querybuilder

SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird
https://sqlkata.com
MIT License
3.09k stars 498 forks source link

System.Data.SqlClient.SqlException: 'Incorrect syntax near '`'.' #578

Closed talley closed 2 years ago

talley commented 2 years ago
public List<Users2> GetUsers()
    {
         SqlConnection sqlcon = new SqlConnection(CONN_STR);
         var compiler = new MySqlCompiler();
        var db = new QueryFactory(sqlcon, compiler);

        var users = db.Query("Users2").Get<Users2>(); //error occurred here

        return users.ToList();
    }
digitaldirk commented 2 years ago

I believe you need to change your compiler type depending on what you are using. In my case I changed MySqlCompiler to SqlServerCompiler.

    {
         SqlConnection sqlcon = new SqlConnection(CONN_STR);
         var compiler = new SqlServerCompiler();
         var db = new QueryFactory(sqlcon, compiler);
         var users = db.Query("Users2").Get<Users2>(); //error occurred here
        return users.ToList();
    }
ahmad-moussawi commented 2 years ago

as per @digitaldirk your connection and compiler should match, you are using SqlConnection (for SqlServer) and using MySqlCompiler (for MySql)

SqlConnection -> SqlServerCompiler MySqlConnection -> MySqlCompiler

talley commented 2 years ago

Thank you. I don`t know how i missed this.