Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Dapper with Oracle

Tags:

c#

oracle

dapper

We use Oracle as our database provider and have looked into replacing some of our data access layer (hard to maintain, harder to merge XSD's) with a saner repository based pattern using Dapper at the bottom layer. However, we have hit a number of issues when using it with oracle.

  • Named Parameters: these seem to be ignored, whenever they are used in a query Oracle seems to interpret them in any order it fancies. The SqlMapper returns correctly named parameters, they just aren't interpreted correctly in Oracle

  • The "@" naming convention for variables is incompatible with oracle named parameters. It expects to see ":" in front of any parameters

Has anybody previously encountered this and have any workarounds?

like image 773
Wolfwyrd Avatar asked Jun 02 '11 09:06

Wolfwyrd


People also ask

Does dapper work with Oracle?

Using oracle database with . net core can be a hassle. By connecting oracle with dapper as a micro orm, life can get easy. Here we will discuss some effective way to establish a connection with oracle database using .

Does dapper work with MySQL?

Work with any database - SQL Server, Oracle, SQLite, MySQL, PostgreSQL etc. For an existing database, using Dapper is an optimal choice.

Is Dapper a micro ORM?

Dapper is a popular open-source, micro-ORM solution that is compatible with the . NET application framework. It lets you work with strongly typed data that constantly changes without spending hours writing code. It is especially useful when dealing with unnormalized databases.

Why Dapper is micro ORM?

Dapper is an example of Micro ORM, in fact, it is called the King of Micro ORM because of its speed and ease of work. First, it creates an IDbConnection object and allows us to write queries to perform CRUD operations on the database.


1 Answers

IMO, the correct approach here is not to (as per the accepted answer) use the database specific parameter prefix (so @ for sql-server, : for oracle) - but rather: use no prefix at all. So ultimately this is:

il.Emit(OpCodes.Ldstr, prop.Name);

(etc)

In particular, a static property would be bad as it would limit you to one vendor per AppDomain.

Dapper has been updated with this change. It also now dynamically detects BindByName and sets it accordingly (all without needing a reference to OracleCommand).

like image 158
Marc Gravell Avatar answered Sep 18 '22 16:09

Marc Gravell