Dapper Contrib - Data Annotation - Key

Description

Specifie the property is a key that is automatically generated by the database (Identity Column).

  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. using (var connection = My.ConnectionFactory())
  13. {
  14. connection.Open();
  15. var identity = connection.Insert(new InvoiceContrib {Kind = InvoiceKind.WebInvoice, Code = "Insert_Single_1"});
  16. }