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

dapper ormlite-servicestack servicestack

Question

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.

Accepted Answer

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.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why