dapperdapper-extensionsmicro-orm

Dapper Contrib Insert MySQL Syntax Error


Hey I am getting syntax error in MySQL using Dapper.Contrib

MySQL server version for the right syntax to use near '[cause_code],[cause_name]) values ('000-DDH', 'No Money')' at line 1

the correct syntax for Insert in mysql is

"Insert Into `tbl_cause` (`cause_code`, `cause_name`) VALUES('blah', 'blah')"; 

my code:

var entity = new Cause { cause_code = "000-DDH", cause_name = "No Money" };
        using (IDbConnection cn = ConStr.Conn()) 
        {
            long ins = cn.Insert(entity);
            if (ins > 0)
            {
                MessageBox.Show("Cause Code: " + entity.cause_code + " Successfully Added!");
                GDRD();
            }
            else {
                MessageBox.Show("Cause Code: " + entity.cause_code + " While trying to Add an Error Occurred!");
            }
        }

how to solve this? thanks in Advance


Solution

  • It's you again :) Does the class Cause have a Table("tbl_cause") directive? Read the dapper contrib extensions documentation here