File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 11# Dapper.FluentColumnMapping
22Fluent 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+ ```
You can’t perform that action at this time.
0 commit comments