dapper - 如何使用 Dapper.SimpleCrud 设置模式名称?
问题描述
我正在使用 Dapper.SimpleCrud。有谁知道如何设置表的模式名称?我查看了文档,但没有找到与设置或更改架构名称相关的任何内容。
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; }
}
解决方案
这是在 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")]
。
推荐阅读
- responsive-design - Material ui makestyles 中的响应式排版
- reactjs - 仅在第二次 onPress 后更新状态
- java - Java.lang.ClassNotFoundException:在路径上找不到类“com.example.dependencyinjection.MainActivity”
- php - PHP日期更改strtotime不能正常工作
- database-design - SqlAlchemy Core:多次定义一对一关系
- c# - 将参数从视图模型传递到另一个
- javascript - JWT 本地存储, Cookies 和页面重载
- r - R组合一个变量的更多类别
- python - 如何在将行推送到 pgsql 之前验证行是否符合要求?
- pdf - 如何使用 Adobe Acrobat 阅读 PDF 的内容?