Dapper Plus – Introduction

Library Under Construction (Available at the end of April)

Dapper Plus Mapper allow mapping the conceptual model (Entity) with the storage model (Database).

Name Description
Identity Sets column(s) which the database generates value. The value is outputted from the destination table (insert and merge action).
Ignore Sets column(s) to ignore.
Key Sets column(s) to use for Primary Key (update, delete, and merge action).
Map Sets column(s) to input to the destination table.
Output Sets column(s) to output from the destination table (insert, update, and merge action).
Table Sets the destination table or view name (including schema).

Dapper Plus – Mapper – Identity

Sets column(s) which the database generates value. The value is outputted from the destination table (insert and merge action).

Example

Identity column

DapperPlusManager.Entity()
                 .Identity(x => x.OrderID);

Dapper Plus – Mapper – Ignore

Sets column(s) to ignore.

Example

Ignore single column

DapperPlusManager.Entity()
                 .Ignore(x => x.Column1);

Ignore many columns


DapperPlusManager.Entity()
                 .Ignore(x => new { x.Column1, x.Column2, x.Column3 });

Dapper Plus – Mapper – Key

Sets column(s) to use for Primary Key (update, delete, and merge action).

Example

Single Key

DapperPlusManager.Entity()
                 .Key(order => order.OrderID);

Composite Key

DapperPlusManager.Entity()
                 .Key(order => new { order.ApplicationID, order.OrderCode });

Dapper Plus – Mapper – Map

Sets column(s) to input to the destination table.

Example

Map with an anonymous type. Sets the property name only if different from the database.

DapperPlusManager.Entity()
                 .Map(order => new { qty = order.TotalQuantity, order.TotalPrice });

Map with hardcoded string

DapperPlusManager.Entity()
                 .Map(order => order.TotalQuantity, "qty")
				 .Map(order => order.TotalPrice, "TotalPrice");

Map with constant value

DapperPlusManager.Entity()
                 .Map(order => new { ConstantColumn1 = 1)
				 .Map(order => 2, "ConstantColumn2");

Map with formula

DapperPlusManager.Entity()
                 .Map(order => new { AvgPrice1 = order.TotalPrice/order.TotalQuantity })
                 .Map(order => order.TotalPrice / order.TotalQuantity, "AvgPrice2");
DapperPlusManager.Entity()
                 .Map(order => order.TotalQuantity, "qty")
				 .Map(order => order.TotalPrice, "TotalPrice");

Dapper Plus – Mapper – Output

Sets column(s) to output from the destination table (insert, update, and merge action).

Example

Output single column

DapperPlusManager.Entity()
                 .Output(order => order.Column1);

Output many columns

DapperPlusManager.Entity()
                 .Output(order => new { order.Column1, order.Column2, order.Column3 });

Dapper Plus – Mapper – Table

Sets the destination table or view name (including schema).

Example

By default, the name mapped is singular.

DapperPlusManager.Entity()
                 .Table("zzz.customers");