c# - How do I bind underscore table/column names automatically using Dapper-Extensions? -


i naming mysql tables , columns using underscore characters:

this_is_a_table should map to: thisisatable

this_is_a_column should map to: thisisacolumn

dapper can handle mapping if set:

defaulttypemap.matchnameswithunderscores = true; 

is there way enable in dapper-extensions maps undescore automatically?

it's pretty strait forward, need create custom mapping. here example:

create table:

create table hello_world (     id int not null,     value_column varchar(max) ) 

test:

public class world {     public int id { get; set; }     public string value { get; set; } }  public class worldcustommapper : classmapper<world> {     public worldcustommapper()     {         base.table("hello_world");         map(f => f.id).column("id");         map(f => f.value).column("value_column");     } }  [testfixture] public class class1 {     [test]     public void testmappping()     {         var conn = new sqlconnection(@"data source=.\sqlexpress; integrated security=true; initial catalog=mydb");         conn.open();          var record = new world         {             id = 1,             value = "hi"         };          conn.insert(record);          var result = conn.get<world>(1);          assert.that(result.value, is.equalto("hi"));      } } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -