Dapper Tutorial Dapper Contrib - Data Annotation - Table


The Table attribute can be used to decorate a data model class to specify the name of the database table that the class represents. It specifies the destination table name mapped to the entity.

  • By default, the pluralized name of the class is used as a table name.
  • You can use another table name by specifying the Table attribute.

In the following example, we are using the Table attribute to map the InvoiceContrib class to the Invoice table in the database.

public class InvoiceContrib
	public int InvoiceID { get; set; }

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

	public string FakeProperty { get; set; }

using (var connection = My.ConnectionFactory())

	var invoice = connection.Get<InvoiceContrib>(1);