I am trying to do CRUD operations using Dapper Extensions. But I am getting error while inserting data to MySQL database as follows:
Error: 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 [......] at line [....]
If I use MSSQL database, Dapper Extensions is working correctly. Why I am getting this error with MySQL?
The error is because Dapper Extensions is generating the query for SQL server (by default) where as you are actually connected to MySQL. There are syntax differences between these two RDBMSs and hence the error. You have to tell Dapper Extensions that you are connecting to MySQL.
Set the Dialect at the startup of your application somewhere.
//Synchronous DapperExtensions.DapperExtensions.SqlDialect = new DapperExtensions.Sql.MySqlDialect(); //Asynchronous DapperExtensions.DapperAsyncExtensions.SqlDialect = new DapperExtensions.Sql.MySqlDialect();
As you can note, you need to configure this separately for synchronous and asynchronous methods. You can read more about this on github.
This will instruct Dapper Extensions to generate the queries according to the syntax of MySql. Not only Dapper Extensions, similar is necessary for many ORMs those support query generation for multiple RDBMSs.