EonaCat.Wrapper.Dapper 1.0.0

Prefix Reserved
dotnet add package EonaCat.Wrapper.Dapper --version 1.0.0
                    
NuGet\Install-Package EonaCat.Wrapper.Dapper -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EonaCat.Wrapper.Dapper" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EonaCat.Wrapper.Dapper" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="EonaCat.Wrapper.Dapper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EonaCat.Wrapper.Dapper --version 1.0.0
                    
#r "nuget: EonaCat.Wrapper.Dapper, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=EonaCat.Wrapper.Dapper&version=1.0.0
                    
Install EonaCat.Wrapper.Dapper as a Cake Addin
#tool nuget:?package=EonaCat.Wrapper.Dapper&version=1.0.0
                    
Install EonaCat.Wrapper.Dapper as a Cake Tool

EonaCat.Wrapper.Dapper

Generic Repository using Dapper for .Net Core, .Net Framework, .Net Standard and many more. This library is a wrapper around Dapper that provides a generic repository for CRUD operations. It also provides a way to work with stored procedures.

It supports MicrosoftSQL, MySql, Oracle, PostGreSql and SqLite databases.

Usage

Key Description
parameters Refers to the key-value pairs that are required when calling a method.
excludeColumns name of the columns that you want to exclude when updating or inserting data.
T entity T represent the table/entity.
public interface IRepository<T>
{
	Task<IEnumerable<T>> GetAllAsync();
	Task<IEnumerable<T>> GetAllAsync(Dictionary<string, object> parameters);
	Task<T> GetAsync(Dictionary<string, object> parameters);
	Task<int> InsertAsync(T entity, params string[] excludeColumns);
	Task<int> UpdateAsync(Dictionary<string, object> parameters, T entity, params string[] excludeColumns);
	Task<int> InsertOrUpdateAsync(Dictionary<string, object> parameters, T entity, params string[] excludeColumns);
	Task<int> DeleteAsync(Dictionary<string, object> parameters);
}
  • Update, Insert and Delete returns number of rows affected after executing the method
  • This is how your specific repository declaration could look like :
public class ProductRepository
{
  private readonly IRepository<Product> _productRepository;
  private readonly string _tableName = "dbo.Products";

  public ProductRepository(string connectionString, database database)
  {
    _productRepository = new Repository<Product>(_tableName, connectionString, database);
  }
}
  • Database names
public enum Database
{
  MicrosoftSQL = 1,
  MySql = 2,
  Oracle = 3,
  SqLite = 4,
  PostGreSql = 5
}
  • Your method implementation could look like this :
public async Task<IEnumerable<Product>> GetAllProductsAsync()
{
  return await _productRepository.GetAllAsync();
}

public async Task<Product> GetProductAsync(Dictionary<string, object> parameters)
{
	return await _productRepository.GetAsync(parameters);
}

public async Task<int> UpdateProductAsync(Dictionary<string, object> parameters, Product product, params string[] excludeColumns)
{
	return await _productRepository.UpdateAsync(parameters, product, excludeColumns);
}
  • Example on how to call the method to insert a new product:
var product = new Product
{
	Id = "52a55d78-fe76-49f0-83f0-378038d2d9a6",
	Name = "Product 1",
	Description = "Product 1 Description",
	Manufacturer = "Manufacturer 1",
	Color = "Red",
	EntryDate = DateTime.Now,
	Ingredients = "Ingredients 1",
	Type = "Collection",
};

var affectedRows = await UpdateProductAsync(parameters, product, "Id");
    • Example on how to call the method to update a product:
var parameters = new Dictionary<string, object>
{
    {"Id","52a55d78-fe76-49f0-83f0-378038d2d9a6"} //"Id" is the column name in the database and the value is the unique identifier of the record you want to fetch
                                                  // Here you can add more parameters if you want
}

var currentProduct = await GetProductAsync(parameters);
if (currentProduct != null)
{
	currentProduct.Name = "Product 2";
	currentProduct.Description = "Product 2 Description";
	currentProduct.Manufacturer = "Manufacturer 2";
	currentProduct.Color = "Blue";
	currentProduct.EntryDate = DateTime.Now;
	currentProduct.Ingredients = "Ingredients 2";
	currentProduct.Type = "Collection";

	// Update the product
	var affectedRows = await UpdateProductAsync(parameters, currentProduct, "Id");
}
else
{
	// Product not found
}

Stored Procedures

Usage

Key Description
connectionString A connection string is a string that specifies information about a data source, means of connecting to it.
database Enum that contains different database provider names ie MicrosoftSQL, MySql, Oracle, PostGreSql, SqLite.
storedProcedureName Name of the stored procedure that will be using to query/manipulate data.
parameters These are key-value pairs that are required when calling stored procedure.
object Key-value pairs/object that consist of a name(s) that are tied to the stored procedure variable(s).
T entity T is the model.
public interface IStoredProcedure
{
  Task<IEnumerable<T>> GetDataAsync<T>(string storedProcedureName, object parameters = null);
  Task<int> ExecuteAsync(string storedProcedureName, object parameters);
  Task<int> ExecuteInBulkAsync(string storedProcedureName, object @object );
}
  • Parameters are optional on the created stored procedure
  IStoredProcedure storedProcedure = new StoredProcedure(ConnectionString, database.PostGreSql);
  • GetDataAsync returns a list of data from the stored procedure
  var results = await storedProcedure.GetDataAsync<Product>("GetProducts");
  • ExecuteAsync() and ExecuteInBulkAsync() returns the number of rows affected after executing the stored procedure.
  var results = await storedProcedure.ExecuteAsync("InsertProduct", new { Name = "Product 1", Description = "Product 1 Description", Manufacturer = "Manufacturer 1", Color = "Red", EntryDate = DateTime.Now, Ingredients = "Ingredients 1", Type = "Collection" });
  var productList = ProductList();  // data type : List<ProductModel>
  var dataTable = DataTableHelper.MapToDataTable(productList);
			// OR
  var dataTable = DataTableHelper.MapToDataTable(GetJsonData()); //takes json data
  var model = new { productType = dataTable };
  var results = await storedProcedure.ExecuteInBulkAsync(storedProcedureName, model);

ExecuteInBulkAsync example

async Task<int> ExecuteInBulkAsync(string storedProcedureName, object model);
  • Construct a model that will be used to map the data into a DataTable.
  • The model should have the same properties as the stored procedure variables.
public static class DataTableHelper
{
  public static DataTable MapToDataTable<T>(List<T> list); // maps any model into DataTable
  public static DataTable MapToDataTable(string jsonObject); // maps json data into DataTable
}
  var productList = productList();  // data type : List<ProductModel>
  var dataTable = DataTableHelper.MapToDataTable(productList);
            // OR
  var dataTable = DataTableHelper.MapToDataTable(GetJsonData()); //takes json data

  var model = new { productType = dataTable };
  var results = await storedProcedure.ExecuteInBulkAsync(storedProcedureName, model);
  • NOTICE :
  • productType is the variable name in the stored procedure.
  • This name should match the variable name in the stored procedure. (Variable name is case sensitive).
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 196 3/6/2025

Generic Repository using Dapper for .Net Core, .Net Framework, .Net Standard and many more. This library is a wrapper around Dapper that provides a generic repository for CRUD operations.
It also provides a way to work with stored procedures.
It supports MicrosoftSQL, MySql, Oracle, PostGreSql and SqLite databases.