Hi.
I would like to use Dapper to have db agnostic code used for e.g. PostgreSQL and Oracle with as little db flavored code as possible. This INSERT code is running without problems for SQL-server and PostgreSQL:
var item = new Item { Name = "Test Name", Number = "Test Number" };
await Connection.ExecuteAsync(@"INSERT INTO Table (Name, Number) VALUES (@Name, @Number);", item);
On Oracle (version 11 xe), I get an ORA-00936: missing expression.
Do I need tailoring using DynamicParameters or the likes?
Hello @unipeg.
Since this is using a OracleCommand of CommandType.Text
, you should precede the parameter name with a colon (:).
That would look like:
c#
var item = new Item { Name = "Test Name", Number = "Test Number" };
await Connection.ExecuteAsync(@"INSERT INTO Table (Name, Number) VALUES (:Name, :Number)", item)
Please refer to the docs for greater details.
my DapperExtensions can reslove your problem
https://github.com/znyet/DapperExtensions
Answered above, closing out to cleanup!
Most helpful comment
Hello @unipeg.
Since this is using a OracleCommand of
CommandType.Text
, you should precede the parameter name with a colon (:).That would look like:
c# var item = new Item { Name = "Test Name", Number = "Test Number" }; await Connection.ExecuteAsync(@"INSERT INTO Table (Name, Number) VALUES (:Name, :Number)", item)
Please refer to the docs for greater details.