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?

2
  • you should manually do this in code. Commented Jun 27, 2016 at 7: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 Commented Jun 27, 2016 at 7:11

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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 :.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.