Search code examples
servicestackdapperormlite-servicestack

Map to custom column names with ServiceStack OrmLite (Without Attributes)


Per title - Is it possible to map

class Test {
   String SomeName {get; set;}
}

to SQL Table

tbl_test (name)

I am not interested to use attributes as I don't want to fill my POCOs with garbage.

Thanks.


Solution

  • Since all ServiceStack libraries use the metadata API's in ServiceStack.Text, all attributes can also be added decoupled from the model itself using the fluent API below:

    typeof(Test)
        .AddAttributes(new AliasAttribute("tbl_test"));
    

    To add attributes on a property you can use the GetProperty() extension method, e.g:

    typeof(Test)
        .GetProperty("SomeName")
        .AddAttributes(new AliasAttribute("p_some_name"));
    

    These attributes need to be run once on Startup before they're accessed by any ServiceStack library.