Database abstraction level in C # for MySQL?

I am trying to use MySQL 5 with C #. I downloaded the MySQL driver on mysql.com and installed it. Now I can connect to MySQL in C # with the following code.

    string ConString = "SERVER=192.168.10.104;";
    ConString += "DATABASE=test;";
    ConString += "UID=user;";
    ConString += "PASSWORD=password;";

    MySqlConnection connection = new MySqlConnection(ConString);

    MySqlCommand command = connection.CreateCommand();
    MySqlDataReader Reader;
    command.CommandText = "select * from j_people";
    connection.Open();

    Reader = command.ExecuteReader();

The problem is that if I change the database server to MS SQL Server or Oracle later?

Is there a database abstraction layer in C #?

I assume that it will be ADO.NET , but I can not find a practical example of ADO.NET with MySQL.

+3
source share
6 answers

... , ///, , MySQL. (MS SQL Server Oracle), . , .

, : LINQ NHibernate ADO .. , , .

public interface IDataLayer
{
    IList<Data> GetData();
    void SaveData(Data dataToSave);
    void DeleteData (Data dataToDelete);
}

public class MySqlDataLayer : IDataLayer
{
    public IList<Data> GetData()
    {
        //Use MySQL connector to get data.
        return data;
    }

    public void SaveData(Data dataToSave)
    {
        //Use MySQL connector to save to data.
    }

    public void DeleteData(Data dataToDelete)
    {
        //Use MySQL connector to delete passed in data.
    }
}
+5
+2

iBatis.NET. , iBatis , Hibernate/Linq, , SQL, iBatis - .

+1

:

  • .NET, , MySql, IDbConnection, IDbCommand, IDataParameters .. , , , MySql, ( factory, Oracle, SQL Server RDBMS.

  • .NET , SQL, , . , "" SQL . SELECTS, INSERTS UPDATES , , , . , ORM. - SQL .

+1

API- MySQL.NET -, System.Data (IDbConnection, IDbCommand ..).

Gateway, API . IoC, Castle, StructureMap .. .

0

Source: https://habr.com/ru/post/1721916/


All Articles