使用 ServiceStack OrmLite(无属性)映射到自定义列名称
Map to custom column names with ServiceStack OrmLite (Without Attributes)
每个标题 - 是否可以映射
class Test {
String SomeName {get; set;}
}
到SQLTable
tbl_test (name)
我对使用属性不感兴趣,因为我不想用垃圾填满我的 POCO。
谢谢。
由于所有 ServiceStack 库都使用 ServiceStack.Text 中的元数据 API,所有属性也可以使用下面的流畅 API 添加,与模型本身分离:
typeof(Test)
.AddAttributes(new AliasAttribute("tbl_test"));
要在 属性 上添加属性,您可以使用 GetProperty()
扩展方法,例如:
typeof(Test)
.GetProperty("SomeName")
.AddAttributes(new AliasAttribute("p_some_name"));
这些属性需要在启动时 运行 一次,然后才能被任何 ServiceStack 库访问。
每个标题 - 是否可以映射
class Test {
String SomeName {get; set;}
}
到SQLTable
tbl_test (name)
我对使用属性不感兴趣,因为我不想用垃圾填满我的 POCO。
谢谢。
由于所有 ServiceStack 库都使用 ServiceStack.Text 中的元数据 API,所有属性也可以使用下面的流畅 API 添加,与模型本身分离:
typeof(Test)
.AddAttributes(new AliasAttribute("tbl_test"));
要在 属性 上添加属性,您可以使用 GetProperty()
扩展方法,例如:
typeof(Test)
.GetProperty("SomeName")
.AddAttributes(new AliasAttribute("p_some_name"));
这些属性需要在启动时 运行 一次,然后才能被任何 ServiceStack 库访问。