ORM that can connect with 2 BD types (SQL or HANA)

Asked

Viewed 86 times

3

Any suggestion of a ORM or Micro ORM that can connect/manipulate 2 different database types, not Imultaneos?

The scenario: I already have an application that uses SQL, I need to adapt it to accept besides SQL, HANA that also uses PL-SQL, so would not have problems with the querys.

Any hint of a ORM or Micro ORM, in I can set in a configuration the BD in question (SQL or HANA).

  • if you have no problem with the query user or Dapper

  • Dapper can handle that? in my researches I saw that using Factorymethod, implemented in the Dbprovidersfactories class, can be used any class that implements Idbconnection. Here is the reference https://stackoverflow.com/questions/5898711/data-layer-abstract-factory, very old! but if you have an example of how I do this with daaper it would be very helpful!

2 answers

1


I have in a Webapi application where SQL and MYSQL support The implementation is very simple:

I created an Abstract class with the configuration of the two connections inserir a descrição da imagem aqui

Follows code: https://gist.github.com/thiagoloureiro/7d8fab3eed2e5a6f8bb8639a0c65ff54

namespace Data.Dapper.Class
{
    public abstract class BaseRepository
    {
        public string connstringSQL = ConfigurationManager.ConnectionStrings["SqlServerConnString"].ConnectionString;

        public MySqlConnection GetMySqlConnection(bool open = true,
            bool convertZeroDatetime = false, bool allowZeroDatetime = false)
        {
            string cs = "Server=xxx;Port=41890;Database=yyyy;Uid=zzz;Pwd=db;";
            var csb = new MySqlConnectionStringBuilder(cs)
            {
                AllowZeroDateTime = allowZeroDatetime,
                ConvertZeroDateTime = convertZeroDatetime
            };
            var conn = new MySqlConnection(csb.ConnectionString);
            if (open) conn.Open();
            return conn;
        }
    }
}

There in the case of MYSQL:

 using (var db = GetMySqlConnection())
{
    const string sql = @"insert into User (Login, Password, CreatedOn, LastLogon) values (@Login, @Password, NOW(), NOW())";

    db.Execute(sql, new { Login = username, Password = password }, commandType: CommandType.Text);
}

SQL Server:

using (var db = new SqlConnection(connstring))
{
    const string sql = @"insert into [User] ([Login], [Password], [CreatedOn], [LastLogon]) values (@Login, @Password, GETDATE(), GETDATE())";

    db.Execute(sql, new { Login = username, Password = password }, commandType: CommandType.Text);
}

Then in the command line of using I differentiate which DB I want to use.

On my Github I have some things where I used this code:

https://github.com/thiagoloureiro/WebAPIBase/

abs

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.