This was old request raised here on GitHub:
A work around is to provide a TableAttribute on the class in this fashion:
[Table("Schema].[Table")]
The feature was included as stated 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
have a property 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; }
}
You should set this TableAttribute.Schema
property while decorating Entity/POCO with Table
attribute. Decorate your Entity/POCO class with [Table("YourTableName", Schema = "YourSchema")]
.