Dapper error on insert record in Firebird
I'm writing a multidabase application with Firebird and PostgreSQL, using Dapper and ASP.NET MVC (migrating from EF). The C# statements to perform CRUD operations in the PGSQL database work fine. When migrating to Firebird, just changing the concrete connection object from NpgsqlConnection to FbConnection, I receive the following error message when trying to insert a record:
FirebirdSql.Data.FirebirdClient.FbException: Dynamic SQL Error SQL error code = -104 Token unknown - line 1, column 23 [ ---> FirebirdSql.Data.Common.IscException: Dynamic SQL Error SQL error code = -104 Token unknown - line 1, column 23
Then, I tried to isolated the problem, testing the insert statement with pure ADO.NET with FirebirdClient (this works fine):
con.Open();
var SQL = "INSERT INTO UNMEDIDA(CD_UNIDADE, NM_UNIDADE, DS_SIGLA)
VALUES(@CD_UNIDADE, @NM_UNIDADE, @DS_SIGLA);";
var cmd = new FbCommand(SQL, con);
cmd.Parameters.AddWithValue("@CD_UNIDADE", 1);
cmd.Parameters.AddWithValue("@NM_UNIDADE", "AA");
cmd.Parameters.AddWithValue("@DS_SIGLA", "AA");
cmd.ExecuteNonQuery();
con.Close();
After, using Dapper without contrib, just the generic execute (this works fine too):
var SQL = "INSERT INTO UNMEDIDA(CD_UNIDADE, NM_UNIDADE, DS_SIGLA)
VALUES(@CD_UNIDADE, @NM_UNIDADE, @DS_SIGLA);";
object obj = new { CD_UNIDADE = 1, NM_UNIDADE = "AA", DS_SIGLA = "AA" };
con.Execute(SQL, obj);
The error ocurrs when I try to use the generic Insert. Dapper will try to use reflection in to the mapping class to extract field names, to build dynamically a insert statament. Probably this statament generated by Dapper has a sintax error. The following code works with PG and Dapper, but fails with FB:
[Table("UNMEDIDA")]
public class UNMEDIDA
{
[ExplicitKey]
public int CD_UNIDADE { get; set; }
public string NM_UNIDADE { get; set; }
public string DS_SIGLA { get; set; }
}
...
UNMEDIDA obj = new UNMEDIDA { CD_UNIDADE = 1, NM_UNIDADE = "AA", DS_SIGLA = "AA" };
con.Insert(obj);
The code above works fine with Npgsql.
Seens like a error in parameters dynamic generation or something.
This error happens to me too. So, the error continues...