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:

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

Data Annotations

Dapper Contrib allow mapping using Data Annotations:

  1. [Table("Invoice")]
  2. public class InvoiceContrib
  3. {
  4. [Key]
  5. public int InvoiceID { get; set; }
  6. public string Code { get; set; }
  7. public InvoiceKind Kind { get; set; }
  8. [Write(false)]
  9. [Computed]
  10. public string FakeProperty { get; set; }
  11. }
  12. [Table("InvoiceDetail")]
  13. public class InvoiceDetailContrib
  14. {
  15. [ExplicitKey]
  16. public int InvoiceID { get; set; }
  17. public string Detail { get; set; }
  18. }