Dapper Contrib

What’s Dapper Contrib?

Dapper Contrib extend the IDbConnection interface with additional CRUD methods.

Installation

Dapper Contrib is installed through NuGet: https://www.nuget.org/packages/Dapper.Contrib/

Methods

Dapper Contrib extend your IDbConnection interface with additional CRUD methods:

var invoice = connection.Get<InvoiceContrib>(1);
var invoices = connection.GetAll<InvoiceContrib>().ToList();
var identity = connection.Insert(new InvoiceContrib {Kind = InvoiceKind.WebInvoice, Code = "Insert_Single_1"});
var isSuccess = connection.Update(new InvoiceContrib {InvoiceID = 1, Code = "Update_Single_1"});
var isSuccess = connection.Delete(new InvoiceContrib {InvoiceID = 1});
var isSuccess = connection.DeleteAll<InvoiceContrib>();

Data Annotations

Dapper Contrib allow mapping using Data Annotations:

[Table("Invoice")]
public class InvoiceContrib
{
	[Key]
	public int InvoiceID { get; set; }

	public string Code { get; set; }
	public InvoiceKind Kind { get; set; }

	[Write(false)]
	[Computed]
	public string FakeProperty { get; set; }
}

[Table("InvoiceDetail")]
public class InvoiceDetailContrib
{
	[ExplicitKey]
	public int InvoiceID { get; set; }

	public string Detail { get; set; }
}