Dapper: Simple INSERT with Dapper on Oracle

Created on 4 Nov 2018  路  3Comments  路  Source: StackExchange/Dapper

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?

oracle

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.

All 3 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

silkfire picture silkfire  路  4Comments

fishjimi picture fishjimi  路  5Comments

rafakwolf picture rafakwolf  路  5Comments

huobazi picture huobazi  路  4Comments

cpx86 picture cpx86  路  4Comments