Giter Club home page Giter Club logo

dapper.crud's Introduction

Dapper.Crud

Extensions methods for IDbConnection to enable easy Insert, Update, Delete operations using Dapper.

Currently only supports SQL Server databases.

All methods are async.

General Usage

Extension methods Insert, Update, Delete and DeleteAll are available for the IDbConnection interface.

Please remember to use proper disposal of connections:

using (IDbConnection connection = new SqlConnection(Settings.ConnectionString))
{
    // Do your stuff here ;)
}

Insert

Create a new record. Returns an int of the generated Id.

Parameters:

Table name

Method Parameters: An object (just like with Dapper parameters) that has only the fields and values to insert.

int id = await connection.Insert("TestTable", new { TestString = "HI", TestInt = 5 });

Update

Update an number of existing records.

Method Parameters:

Table name

Predicate parameters: Update only the records that have the specified column / value. In the example below, only records that have a value of 5 for the TestTableID column (which happens to be a primary key) will be updated.

Method Parameters: An object that has only the fields and values to update.

 await connection.Update("TestTable", new { TestTableID = 5 }, new { TestString = "UPDATED" });

Delete

Delete a number of records.

Method Parameters:

Table name

Predicate parameters: Delete only the records that have the specified column / value. In the example below, only records that have a value of 5 for the TestTableID column will be deleted (one record since that's a primary key column).

 await connection.Delete("TestTable", new { TestTableID = 5 });

DeleteAll

Delete all records in a database table.

Method Parameters:

Table name

 await connection.DeleteAll("TestTable");

Potential Future Features?

  • Ability to specify database (mysql, etc.) which will adjust how generated ids are returned from Insert etc.

  • Version on Insert that returns GUID ids.

dapper.crud's People

Contributors

jamesmh 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.