Skip to content

ruanbl/Dapper.MicroCRUD

 
 

Repository files navigation

Dapper.MicroCRUD - Lightweight CRUD Extensions for Dapper.Net

Overview

Dapper.MicroCRUD is a small and fast Dapper.Net extension library to perform CRUD statement with POCO models.

Build status

Project aims

  1. Provide fast and lightweight CRUD extensions for Dapper
  2. Should be able to run against multiple different databases in the same project
  3. Thread safety should be guarenteed

I was using the fantastic Dapper.SimpleCRUD library and found it incredibly easy to use. However, two things drove me to write this library - I have a project which uses SqlServer and Postgres databases side-by-side, and unfortunately Dapper.SimpleCRUD does not support this. Second, I found it was missing a few crucial optimizations which was doubling the time taken to easily insert many rows.

Features

Currently, the following DBMS are supported. More will be added (e.g. SQLite) when there is demand for them:

  • Microsoft SqlServer 2012 and above
  • PostgreSQL

CRUD Helpers

Dapper.MicroCRUD provides the following extensions to the IDbConnection (with Async equivalents):

  • Count: Counts how many entities in the table match the conditions.
  • Find: Find an entity by it's id, or null.
  • Get: Get an entity by it's id, or throw an exception.
  • GetRange: Gets all the entities in the table which match the conditions.
  • GetPage: Gets a page of entities which match the conditions.
  • GetAll: Gets all the entities in the table.
  • Insert: Inserts an entity into the table, with the ability to return the generated identity.
  • InsertRange: Efficiently inserts multiple entities.
  • Update: Updates the entity by using it's primary key.
  • UpdateRange: Efficiently updates multiple entities in the database.
  • Delete: Deletes an entity
  • DeleteRange: Deletes the entities which match the given conditions.
  • DeleteAll: Deletes all entities in the table.

Configuration

Documentation in progress!

Don't forget, for practical examples of usage, you can also browse our extensive unit tests suite.

Comparison

NB: These may not be correct nor up-to-date. I made this comparison very quickly

Library Operations Composite Keys Async .Net Core Notes
Dapper.Contrib Get
GetAll
Insert
Update
Delete(All)
✔️ ✔️
  • Can use interfaces to track changes
Dapper.Extensions Get
Insert
Update
Delete
GetList
GetPage/GetSet
Count
✔️
  • Can use simple lambdas and predicates
  • Generates GUID keys
  • Can be configured without attributes
Dapper.FastCRUD Insert
Get
Find(Equivalent to GetRange)
(Bulk)Update
(Bulk)Delete
Count
✔️ ✔️ ✔️
  • Has a nice fluent syntax for complex WHERE operations
  • Can be configured without attributes
Dapper.MicroCRUD Count
Find/Get
Get(Range/All)
GetPage
Insert(Range)
Update(Range)
Delete(Range/All)
✔️ ✔️
  • Can work across multiple DBMS in same project
  • Throws exceptions for inconsistencies (E.g. Update not affected anything)
Dapper.SimpleCRUD Get
GetList
GetListPaged
Insert
Update
Delete(List)
RecordCount
✔️
  • Can create WHERE clauses from objects
  • Generates GUID keys

Installation

Simply add the nuget package Dapper.MicroCRUD to your project.

Licensing and Attribution

See License.

This project was written after using Dapper.SimpleCRUD by Eric Coffman, and borrows it's excellent method conventions and API heavily. The code base is however completely rewritten.

About

CRUD Extensions for Dapper.Net

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%