ADO.DataAccessHelper 1.1.1

Lite and simple ADO.net data access helper with DbProviderFactory.
Samples are at "https://www.codefode.com/2019/11/ado.html"

Install-Package ADO.DataAccessHelper -Version 1.1.1
dotnet add package ADO.DataAccessHelper --version 1.1.1
<PackageReference Include="ADO.DataAccessHelper" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ADO.DataAccessHelper --version 1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

ADO.DataAccessHelper


ADO.DataAccess is .net standard 2.0 class library, lite, simple, and more than one database connections from different technologies made possible with ADO.Net DbProviderFactory.

Few DbProviderFactories

MS SQL      : SqlClientFactory
MySql       : MySqlClientFactory
Oracle      : OracleClientFactory 
PostgreSql  : NpgsqlFactory
....        : ....

Provided features

  • Works for .net Framework 4.6.1 and later.
  • Works for .net core 2.0 and later
  • Helper methods eliminates ADO.net repetitive code for the given DbProvider.
  • Support for asynchronous programming

Example

ADO.DataAccess factory repository to be set at start of the application, it’s an optional and connection can be provided as input parameter to helper method, see Connection Example.

DatabaseProvider<SqlClientFactory>.Set("Sql.Connection1", $"{SqlConnection1String}");
DatabaseProvider<SqlClientFactory>.Set("Sql.Connection2", $"{SqlConnection2String}");
DatabaseProvider<NpgsqlFactory>.Set("PostgreSql.Connection", $"{PostgreSqlConnectionString}");
DatabaseProvider<MySqlClientFactory>.Set("MySql.Connection", $"{MySqlConnectionString}");

Different ways to use pre-set factories in data access layer.
Option#1:

//Default connection is, first connection set for SqlClientFactory
DataSet dataSet = DataAccess<SqlClientFactory>.ExecuteDataSetProcedure("SelectEmployee",
    new SqlParameter[] {
    new SqlParameter("@EmployeeId",7)
});

Option#2:

//Explicit connection name to connect specific database instance with give DbProvider
DataSet dataSet = DataAccess<SqlClientFactory>.Get("Sql.Connection2").ExecuteDataSetProcedure("SelectCustomer",
    new SqlParameter[] {
    new SqlParameter("@CustomerId",7)
});

Option#3:

//Option Three: Default connection is  'PostgreSql.Connection', NpgsqlFactory has one connection
DataAccess<NpgsqlFactory>.ExecuteProcedure("DeleteAllLogs", new NpgsqlParameter[] {
    new NpgsqlParameter("@UserId",7 )
});
Connection Example

Provide connection string while making a call to helper method.
Option#4:

const string ConnectionString = @"Data Source=XYZ\SQLDEV;Initial Catalog=PlayGround;User Id=SA;Password=XXXXX";

//Single line method call 
string name = DataAccess<SqlClientFactory>.ExecuteScalarQuery<string>("Select Name from Employees Where EmployeeId = 7", ConnectionString); 

License

Copyright (C) 2019
(www.codefode.com) Hiten

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/ or https://www.gnu.org/licenses/agpl-3.0.html>.

ADO.DataAccessHelper


ADO.DataAccess is .net standard 2.0 class library, lite, simple, and more than one database connections from different technologies made possible with ADO.Net DbProviderFactory.

Few DbProviderFactories

MS SQL      : SqlClientFactory
MySql       : MySqlClientFactory
Oracle      : OracleClientFactory 
PostgreSql  : NpgsqlFactory
....        : ....

Provided features

  • Works for .net Framework 4.6.1 and later.
  • Works for .net core 2.0 and later
  • Helper methods eliminates ADO.net repetitive code for the given DbProvider.
  • Support for asynchronous programming

Example

ADO.DataAccess factory repository to be set at start of the application, it’s an optional and connection can be provided as input parameter to helper method, see Connection Example.

DatabaseProvider<SqlClientFactory>.Set("Sql.Connection1", $"{SqlConnection1String}");
DatabaseProvider<SqlClientFactory>.Set("Sql.Connection2", $"{SqlConnection2String}");
DatabaseProvider<NpgsqlFactory>.Set("PostgreSql.Connection", $"{PostgreSqlConnectionString}");
DatabaseProvider<MySqlClientFactory>.Set("MySql.Connection", $"{MySqlConnectionString}");

Different ways to use pre-set factories in data access layer.
Option#1:

//Default connection is, first connection set for SqlClientFactory
DataSet dataSet = DataAccess<SqlClientFactory>.ExecuteDataSetProcedure("SelectEmployee",
    new SqlParameter[] {
    new SqlParameter("@EmployeeId",7)
});

Option#2:

//Explicit connection name to connect specific database instance with give DbProvider
DataSet dataSet = DataAccess<SqlClientFactory>.Get("Sql.Connection2").ExecuteDataSetProcedure("SelectCustomer",
    new SqlParameter[] {
    new SqlParameter("@CustomerId",7)
});

Option#3:

//Option Three: Default connection is  'PostgreSql.Connection', NpgsqlFactory has one connection
DataAccess<NpgsqlFactory>.ExecuteProcedure("DeleteAllLogs", new NpgsqlParameter[] {
    new NpgsqlParameter("@UserId",7 )
});
Connection Example

Provide connection string while making a call to helper method.
Option#4:

const string ConnectionString = @"Data Source=XYZ\SQLDEV;Initial Catalog=PlayGround;User Id=SA;Password=XXXXX";

//Single line method call 
string name = DataAccess<SqlClientFactory>.ExecuteScalarQuery<string>("Select Name from Employees Where EmployeeId = 7", ConnectionString); 

License

Copyright (C) 2019
(www.codefode.com) Hiten

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/ or https://www.gnu.org/licenses/agpl-3.0.html>.

  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.1.1 54 12/20/2019
1.0.1 72 11/4/2019