如何使用 Dapper.SimpleCrud 设置架构名称?

How to set Schema name using Dapper.SimpleCrud?

我正在使用 Dapper.SimpleCrud。有谁知道如何为 table 设置架构名称?我查看了文档,但没有找到任何与设置或更改架构名称相关的内容。

public class doc_info
{
    public int doc_info_id { get; set; }
    public int app_info_id { get; set; }
    public string doc_name { get; set; }
    public string file_loc { get; set; }
    public string doc_type { get; set; }
    public string doc_scope { get; set; }
    public int doc_order { get; set; }
}

这是旧请求 here on GitHub:

A work around is to provide a TableAttribute on the class in this fashion:

[Table("Schema].[Table")]

该功能已按说明包含在内here on GitHub

See the tests: https://github.com/ericdc1/Dapper.SimpleCRUD/blob/master/Dapper.SimpleCRUDTests/Tests.cs#L83

[Table("CarLog", Schema = "Log")]
public class CarLog
{
    public int Id { get; set; }
    public string LogNotes { get; set; }
}

public void TestInsertIntoDifferentSchema()
{
    using (var connection = GetOpenConnection())
    {
        var id = connection.Insert(new CarLog { LogNotes = "blah blah blah" });
        id.IsEqualTo(1);
        connection.Delete<CarLog>(id);
     }
}

Class TableAttribute 有一个 属性 Schema:

[AttributeUsage(AttributeTargets.Class)]
public class TableAttribute : Attribute
{
    public TableAttribute(string tableName);

  //
    // Summary:
    //     Name of the table
    public string Name { get; }
    //
    // Summary:
    //     Name of the schema
    public string Schema { get; set; }
}

您应该在使用 Table 属性装饰 Entity/POCO 时设置此 TableAttribute.Schema 属性。用 [Table("YourTableName", Schema = "YourSchema")].

装饰你的 Entity/POCO class