Using schema names with SQL Server & ServiceStack.OrmLite

亡梦爱人 提交于 2020-01-01 08:20:35

问题


Anyone know how to apply the correct Alias attribute to query tables with schema names?

I have a table called accounts.register. I've tried using [Alias("accounts.register")] as the class decorator attribute for Register class but this doesn't work.

If I change the schema to dbo then I can remove the alias and everything works. Unfortunately I have a legacy system with many schemas so I need this to work.


回答1:


OK I figured it out. Along with the Alias attribute is the Schema attribute. The former is in the ServiceStack.DataAnnotations namespace but the latter is in the ServiceStack.OrmLite namespace. Here's an example to map fields field1 & field2 to/from myschema.mytable:

using System;
using ServiceStack.OrmLite;
using ServiceStack.DataAnnotations;

[Schema("myschema")]
[Alias("mytable")]
public class MyEntity
{
    [PrimaryKey]
    [AutoIncrement]
    public long Id { get; set; }

    [Alias("field1")]
    public string SomeField1 { get; set; }

    [Alias("field1")]
    public string SomeField2 { get; set; }
}


来源:https://stackoverflow.com/questions/13945563/using-schema-names-with-sql-server-servicestack-ormlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!