Giter Site home page Giter Site logo

iamahsanmalik / dapperaddons Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 21 KB

Dapper Addons is a set of helpful methods that make a developer's life easier when working with a database. Dapper Addons helps developers to create, update, or delete records without having to worry about opening and closing sql connections, as well as object casting.

Home Page: https://www.nuget.org/packages/DapperAddons/1.0.2

License: MIT License

C# 100.00%

dapperaddons's Introduction

DapperAddons

Dapper is an object–relational mapping product for the Microsoft .NET platform: it provides a framework for mapping an object-oriented domain model to a traditional relational database. Its purpose is to relieve the developer from a significant portion of relational data persistence-related programming tasks

Since the Dipper package is an open source and freely available, why do I need to create this package? Well, you're right. The main purpose behind DapperAddons is to provide convincing, concise methods so that developers become more productive.

What is Dapper Addons Package?

Dapper Addons is a set of helpful methods that make a developer's life easier when working with a database. Dapper Addons include methods such as GetOneAsync, GetOneByStoreProcedureAsync, GetAllAsync, GetAllByStoreProcedureAsync, InserOneAsync and InsertOneByStoreProcedureAsync, UpdateOneAsync and UpdateOneByStoreProcedureAsync, DeleteAsync and DeleteByStoreProcedureAsync to create, update, or delete records without having to worry about opening and closing sql connections, as well as object casting.

How to use Dapper Addons:

Currently Dapper Addons contains two types of methods.

  • 1: Methods to perform CRUD operations via query
  • 2: Methods to perform CRUD operations via store procedure name

Let's start with DbHelpers

  • 1 => : Install DapperAddons Package
  • 2 => : Register AddDapperAddons in services container. To register this package, simply add this code in Program.cs file (Previously this file known as startup.cs) builder.Services.AddDapperAddons();
  • 3 => : Inject IDbhelpers into the constructor of the class in which you want to perform the database operation. To inject IDbhelpers, simply add this code to your constructor
public class YourClass
{
    private readonly IDbHelpers _dbHelpers;
    public YourClass(IDbHelpers dbHelpers)
    {
        _dbHelpers = dbHelpers;
    }
}
  • Congratulations => : You are good to go. Now you can perform any database operation such as inserting, updating, deleting and retrieving data via query or store procedure.
Note: I am writing a few examples to use this package, however more examples will be added soon. Any questions or suggestions are greatly appreciated.
Quick Reminder:

Return type and Input parameters can be simply system or user define data type such as string, class, object or dynamic.

While using this package, you have the option of using Raw SQL Query or name of SQL Store Procedure to get the job done. If you wish to use the stored procedure, call only those methods whose name contains the stored procedure keyword such as GetOneByStoreProcedure, GetAllByStoreProcedure.

Use of GetAllAsync or GetAllByStoreProcedureAsync:
  • Note: You must already inject IDbHelpers to your constructor
public class YourClass
{
    private readonly IDbHelpers _dbHelpers;
    public YourClass(IDbHelpers dbHelpers)
    {
        _dbHelpers = dbHelpers;
    }
}
Now, lets call GetAllAsync method
    string yourQuery = "select * from countries";
    // If you connection string name is DefaultConnection, then there is no need to pass connection string name, else you have to specify the connection string name.
    var result = await _dbHelpers.GetAllAsync(yourQuery);

    // To pass connection string, you must already defined connection string in appsettings.json before to use its name here
    // It will return list of countries Database helper method for retrieving one record from database
    var resultWithDifferentConnectionString = await _dbHelpers.GetAllAsync(yourQuery, "ConnectionStringName");

dapperaddons's People

Contributors

iamahsanmalik avatar

Stargazers

Mudassar Rehman avatar  avatar Faisal Raheem Baloch avatar  avatar Noor Ahmad Khan avatar

Watchers

 avatar Noor Ahmad Khan avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.