Skip to content
schotime edited this page Apr 26, 2012 · 2 revisions

By default no mapping is required. It will be assumed that the table name will be the class name and the primary key will be 'Id' if its not specified with the attributes below.

Basic mapping is done via attributes. The two most used ones are:

  1. [TableName] This takes a "name" parameter which indicates the table for which the Poco class will be mapped to.

  2. [PrimaryKey] This has a "columnName" parameter which takes the column name of the primary key for the table. Multiple primary keys can be specified by separating the columns with a comma. There is also an "autoIncrement" property which is used to indicate whether the primary key column is auto incremented eg. identity column in Sql Server. By default this is true. For Oracle there is also a "sequenceName" property which will be used when inserting data with Oracle.

  3. [Column] This is used if the column name does not match the property name.

  4. [Ignore] This property will be ignored and cannot be mapped to.

  5. [Result] Properties marked with the Result column can be mapped into, however there properties will not be included in inserts or updates. Note: These columns will need to be explicitly specified in the SQL. It will not be included in the auto generated SQL.

Example

[TableName("Users")]
[PrimaryKey("UserId")]
public class User
{
    public int UserId { get;set; }
    [Column("emailAddress")]
    public string Email { get;set; }
    [Result]
    public string ExtraInfo { get;set; }
    [Ignore]
    public int Temp { get;set; }
}

Clone this wiki locally