I'm trying to pass a bool as a parameter to Oracle using Dapper, translating to a 1/0 field on the database, like this:
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
}
But this throws an exception:
System.ArgumentException: 'Value does not fall within the expected range.'
I know I can create another property public int ActiveInt => Active ? 1 : 2;
but I would like to keep my POCO classes as clean as possible, especially because the properties need to be public for Dapper to use them as parameters.
I tried to create a bool type handler, but it only works for query columns, not parameters: https://github.com/StackExchange/Dapper/issues/303
I also need to pass the whole object as parameter, so converting when passing the parameter isn't possible.
Is there a way to do that?