【问题标题】:Using schema names with SQL Server & ServiceStack.OrmLite在 SQL Server 和 ServiceStack.OrmLite 中使用架构名称
【发布时间】:2012-12-06 09:39:39
【问题描述】:

有人知道如何将正确的 Alias 属性应用于具有模式名称的查询表吗?

我有一张名为accounts.register 的表。我尝试使用[Alias("accounts.register")] 作为Register 类的类装饰器属性,但这不起作用。

如果我将架构更改为dbo,那么我可以删除别名并且一切正常。不幸的是,我有一个包含许多模式的遗留系统,所以我需要它来工作。

【问题讨论】:

    标签: sql-server ormlite-servicestack


    【解决方案1】:

    好的,我想通了。与 Alias 属性一起的是 Schema 属性。前者在 ServiceStack.DataAnnotations 命名空间中,而后者在 ServiceStack.OrmLite 命名空间中。这是一个将字段 field1 和 field2 映射到/来自 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; }
    }
    

    【讨论】:

    • 如果您使用的是 T4 POCO 一代,您知道如何让 OrmLite 执行此操作吗?
    • @anaximander 支持最近在版本 4 中添加。github.com/ServiceStack/ServiceStack.OrmLite/commit/… 。如果您想自己添加,可以将 '[Schema("")]' 添加到 '[Alias("")]' 下面的行中并这将添加您需要的架构属性。
    猜你喜欢
    • 2017-03-10
    • 2014-06-22
    • 1970-01-01
    • 2014-10-04
    • 1970-01-01
    • 1970-01-01
    • 2010-09-23
    • 2014-02-12
    • 1970-01-01
    相关资源
    最近更新 更多