1

I have a rather big application using dapper and Oracle. Now, I want to support SQL Server.

The problem is that all my queries are written with : and not with @, so SQL Server complains:

Incorrect syntax near ':'

Is it possible to tell Dapper that it should replace : with @ or do I have to do that in my own code?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Christophe Blin
  • 1,687
  • 1
  • 22
  • 40
  • you should manually do this in code. – Nazir Ullah Jun 27 '16 at 07:10
  • Dapper is just a *very thin* layer on top of your `SqlConnection` or `OracleConnection` - I highly doubt it has any means of replacing parameter naming conventions. That would be something a full ORM like Entity Framework would probably handle for you – marc_s Jun 27 '16 at 07:11

2 Answers2

0

I have found out that this is indeed impossible directly with dapper :

Dapper.net Oracle parameter

Using Dapper with Oracle

Sorry for the duplicates.

Community
  • 1
  • 1
Christophe Blin
  • 1,687
  • 1
  • 22
  • 40
0

This is not built in, but you could provide it relatively simply by writing a custom extension method and doing whatever tweaks you need:

public static IEnumerable<T> MyMagicQuery<T>(this IDbConnection conn,
    string query, object args = ...)
{
    query = RunSomeRegexReplace(query);
    return conn.Query<T>(query, args, ...);
}

However, while the regex for this is not particularly taxing, the bigger problem is that T/SQL and PL/SQL are both distinct variants of SQL. Many features will not work at all when given a simple direct translation. Other features may work, but require different syntax. A third group of features may work syntactically but give different results (yes, really), or have very different performance characteristics unless re-written to exploit RDBMS-specific preferences.

Fundamentally, changing between RDBMS is a lot more than just changing @ to :.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900