这是在 GitHub 上提出的旧请求:
一种解决方法是以这种方式在类上提供 TableAttribute:
[Table("Schema].[Table")]
该功能已包含在 GitHub 上,如下所述:
查看测试: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);
}
}
类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; }
}
您应该在使用属性TableAttribute.Schema
装饰 Entity/POCO 时设置此Table
属性。用 .装饰你的 Entity/POCO 类[Table("YourTableName", Schema = "YourSchema")]
。