【发布时间】:2017-02-21 11:20:03
【问题描述】:
我正在尝试使用 Dapper 将布尔值作为参数传递给 Oracle,转换为数据库上的 1/0 字段,如下所示:
public class Customer
{
public bool Active { get; set; }
}
static void InsertCustomer()
{
var customer = connect.QueryFirst<Customer>("select 1 active from dual"); // this works
connect.Execute("insert into customers(active) values(:active)", customer); // this doesn't
}
但这会引发异常:
System.ArgumentException: '值不在预期范围内 范围。'
我知道我可以创建另一个属性public int ActiveInt => Active ? 1 : 2;,但我希望我的 POCO 类尽可能干净,特别是因为属性需要公开,以便 Dapper 将它们用作参数。
我尝试创建一个 bool 类型的处理程序,但它只适用于查询列,不适用于参数:https://github.com/StackExchange/Dapper/issues/303
我还需要将整个对象作为参数传递,所以在传递参数时转换是不可能的。
有没有办法做到这一点?
【问题讨论】: