Nju
Nju

Reputation: 629

How to connect to different type of database in .NET Core

I found this site https://blogs.msdn.microsoft.com/dotnet/2016/11/09/net-core-data-access/ but if I can use one variable to holed the different connection? For example I have MySQL and SQLite. So I write var connection = new SqliteConnection() and var connection = new MySqlConnection() but I need this variable connection as argument for functions. Can I somehow make it? And object does not help :(

Upvotes: 0

Views: 734

Answers (1)

Martin Ullrich
Martin Ullrich

Reputation: 100731

Both SqliteConnection and MySqlConnection inherit from DbConnection which you can use as parameter type. For even more abstraction: this type also implements IDbConnection

Upvotes: 1

Related Questions