Skip to content

Commit 792528b

Browse files
committed
Adding brief info on how to use the library
1 parent 4dd6fac commit 792528b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,33 @@
11
# Dapper.FluentColumnMapping
22
Fluent Object-Column Mappings for use with Dapper
3+
4+
5+
## How to use
6+
7+
```c#
8+
// Create yourself a new mapping collection
9+
var mappings = new ColumnMappingCollection();
10+
11+
// Start defining the mappings between each property/column for a type
12+
mappings.RegisterType<State>()
13+
.MapProperty(x => x.Id).ToColumn("STATE_CD")
14+
.MapProperty(x => x.Name).ToColumn("STATE_DESCRIPTION")
15+
.MapProperty(x => x.Country).ToColumn("STATE_COUNTRY");
16+
17+
// You can add multiple type mappings to a collection too
18+
mappings.RegisterType<UserActivityEvent>()
19+
.MapProperty(x => x.EventId).ToColumn("ACTIVITY_ID")
20+
.MapProperty(x => x.User.Id).ToColumn("USER_ID")
21+
.MapProperty(x => x.ActivityDate).ToColumn("ACTIVITY_DATE")
22+
.MapProperty(x => x.ActivityType).ToColumn("ACTIVITY_TYPE")
23+
.MapProperty(x => x.Details).ToColumn("DETAILS");
24+
25+
// Tell Dapper to use our custom mappings
26+
mappings.RegisterWithDapper();
27+
28+
// Grab our data from the database
29+
IEnumerable<State> states;
30+
using (var dbConnection = CreateNewConnection())
31+
states = dbConnection.Query<State>("SELECT * FROM STATES");
32+
33+
```

0 commit comments

Comments
 (0)