SQL Server How can I use Dapper in a multi database environment?

db2dz4w8  于 12个月前  发布在  其他
关注(0)|答案(2)|浏览(118)

I'm trying to implement simple queries like SELECT * FROM TABLE_X WHERE XID = @id , but the problem that I'm having is that these queries would run on different databases (SQL Server and Oracle) for different application instances.

How to do it without to have to write each database a new set of queries?

vlurs2pr

vlurs2pr1#

Dapper is really close to the database, and allow you to leverage pure SQL tricks specific for a specific database. In my opinion you should use a query object pattern, so you will have an interface in front of each extraction /commit that would possibly change for SQL/Oracle.

oxcyiej7

oxcyiej72#

I've downloaded the code of SqlMapper.cs and hacked SetupCommand to check if the command is from Oracle or SQL Server.

That was what I did:

if (cnn.GetType().Name.ToLowerInvariant().Contains("oracle"))
{
    sql = sql.Replace('@', ':');
}

相关问题