Dapper Contrib - Data Annotation - ExplicitKey

Description

Specifie the property is a key that is NOT automatically generated by the database.

  1. [Table("InvoiceDetail")]
  2. public class InvoiceDetailContrib
  3. {
  4. [ExplicitKey]
  5. public int InvoiceID { get; set; }
  6. public string Detail { get; set; }
  7. }
  8. using (var connection = My.ConnectionFactory())
  9. {
  10. connection.Open();
  11. var invoice = new InvoiceContrib {Kind = InvoiceKind.WebInvoice, Code = "Insert_Single_1"};
  12. connection.Insert(invoice);
  13. var invoiceDetail = new InvoiceDetailContrib {InvoiceID = invoice.InvoiceID, Detail = "Insert_Single_1"};
  14. connection.Insert(invoiceDetail);
  15. }