Dapper.SimpleCRUD mysql small episode when inserting data

Recently, I wanted to play .net dapper, and then I searched the nuget package and saw  Dapper.SimpleCRUD  . Then I waited for the curious little year, and I began to be eager to try again.

I have no problems using the sqlserver database. Since there is no problem with sqlserver, what about mysql?

Curiosity killed the cat, so give it a try, oh shit! The other party doesn't want to talk to you and throws an exception for you.

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 '[users] ([UserName], [Pwd], [Slat], [UserType], [Stat], [CreateTime], [LastLogin' at line 1

The general meaning of the exception is: buddy, your sql statement has a syntax error

The exception is as follows:

 

Fortunately, the error was pointed out in this exception. The table name and field name in the sql statement actually have square brackets. This thing is no problem in sqlserver, but there are no square brackets in mysql. mysql uses `` this thing, tab The one above the key. So the question is, how to change it?

Use the following line of code to solve this problem

Dapper.SimpleCRUD.SetDialect(Dapper.SimpleCRUD.Dialect.MySQL);

Because Dapper.SimpleCRUD defaults to sqlserver for Dialect, after setting Dialect to mysql, everything is calm and natural.

Here is a record of the problem encountered this time, and I hope it can help you

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325362711&siteId=291194637