Using schema names with SQL Server & ServiceStack.OrmLite

后端 未结 1 976
花落未央
花落未央 2021-02-19 23:36

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 [A

1条回答
  •  既然无缘
    2021-02-20 00:30

    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; }
    }
    

    0 讨论(0)
提交回复
热议问题