GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - godsharp/GodSharp.Data.Common.DbProvider: DbProviderFactory Factory libary for .NET Core.

BranchesTags
Open more actions menu

Latest commit

 

History

4 Commits
4 Commits

Folders and files

NameName
Last commit message
Last commit date
src/GodSharp.Data.Common.DbProvider
src/GodSharp.Data.Common.DbProvider
 
 
test/GodSharp.Data.Common.DbProvider.ConsoleApp
test/GodSharp.Data.Common.DbProvider.ConsoleApp
 
 
.gitignore
.gitignore
 
 
GodSharp.Data.Common.DbProvider.sln
GodSharp.Data.Common.DbProvider.sln
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
appveyor.yml
appveyor.yml
 
 

Repository files navigation

GodSharp.Data.Common.DbProvider

DbProviderFactory Factory libary for .NET Core.

AppVeyor build status NuGet MyGet

Supported netstandard1.3 and netstandard2.0.

Getting Started

  1. Install Nuget Package.

See here.

  1. Add Json Parameters.

You can add to any json file,and then add this file.

Parameters format like below.

{
  "DbConnectionStrings": [
    {
      "name": "mssql",
      "connectionString": "Data Source=localhost;Initial Catalog=Master;User Id=sa;Password=1234;",
      "providerName": "System.Data.SqlClient"
    },
    {
      "name": "mysql",
      "connectionString": "Data Source=localhost;Initial Catalog=user;User Id=root;Password=1234;",
      "providerName": "Pomelo.Data.MySql"
    },
    {
      "name": "sqlite",
      "connectionString": "Data Source=data.db",
      "providerName": "Microsoft.Data.Sqlite"
    },
    {
      "name": "pgsql",
      "connectionString": "Host=localhost;Database=postgres;Username=postgres;Password=1234;",
      "providerName": "Npgsql"
    }
  ],
  "DbProviderFactories": [
    {
      "name": "SqlClient Data Provider",
      "invariant": "System.Data.SqlClient",
      "description": ".Net Framework Data Provider for SqlServer",
      "type": "System.Data.SqlClient.SqlClientFactory, System.Data.SqlClient"
    },
    {
      "name": "MySQL Data Provider by Pomelo",
      "invariant": "Pomelo.Data.MySql",
      "description": ".Net Framework Data Provider for MySql",
      "type": "Pomelo.Data.MySql.MySqlClientFactory, Pomelo.Data.MySql"
    },
    {
      "name": "SQLite Data Provider",
      "invariant": "Microsoft.Data.Sqlite",
      "description": ".Net Framework Data Provider for SQLite",
      "type": "Microsoft.Data.Sqlite.SqliteFactory, Microsoft.Data.Sqlite"
    },
    {
      "name": "Npgsql Data Provider",
      "invariant": "Npgsql",
      "description": ".Net Framework Data Provider for PostgreSql",
      "type": "Npgsql.NpgsqlFactory, Npgsql"
    }
  ]
}

Tips:DbConnectionStrings section is not required,but I strongly recommend you add this.

  1. Load DbProviders and DbConnectionStrings[option].
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
// add json file
.AddJsonFile("db.provider.json");

var config = builder.Build();

// Load DbProviders and DbConnectionStrings
DbProviderManager.LoadConfiguration(config);
  1. Get DbConnectionString.
DbConnectionStringSetting conn = DbConnectionStringManager.ConnectionStrings["sqlite"];
  1. Get DbConnectionFactory.
DbProviderFactory factory = DbProviderFactories.GetFactory(conn.ProviderName);
  1. Use DbProviderFactory create IDbConnection and other.

Create IDbConnection

IDbConnection db = factory.CreateConnection();

Use IDbConnection.

db.ConnectionString = conn.ConnectionString;
db.Open();

var cmd = db.CreateCommand();
cmd.CommandText = "select datetime('now');";
var dt = cmd.ExecuteScalar();
System.Console.WriteLine(dt);

db.Close();

You can see the full code in test.

About

DbProviderFactory Factory libary for .NET Core.

Topics

dbconnectionstringsdbproviderdbproviderfactoriesdbproviderfactory

Resources

Readme
MIT license
Activity
Custom properties

Stars

9 stars

Watchers

3 watching

Forks

6 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.