I am using Oracle Managed Data Access components Code First
Attempting to convert Int16 to Boolean but always receive an exception
'The 'property name' property on 'class name' could not be set to 'System.Int16' value. You must set this property to a non-null value of the 'System.Boolean'
If I have a boolean as a property within my POCO and use either SqlQuery of the DbSet or manually create a datareader I receive a cast exception
Interestingly if I use normal EF such as
var test = dbContext.Set<Person>().Where(c=> 1==1).ToList();
no exceptions are thrown and the expected property values are set.
A basic model
public class Person
{
[Key]
public int Id { get; set; }
public bool Active { get; set; }
}
The call ToList raises the exception
static void Main(string[] args)
{
var dbContext = new Context();
var sql = "select 1 Id, cast(1 as Number(1,0)) Active from dual";
var query = dbContext.Set<Person>().SqlQuery(sql);
var list = query.ToList();
}
I've defined edmMappings (I don't think this matters) in my config file as follows:
<oracle.manageddataaccess.client>
<version number="*">
<edmMappings>
<edmNumberMapping>
<add NETType="bool" MinPrecision="1" MaxPrecision="1" DBType="Number" />
<add NETType="byte" MinPrecision="2" MaxPrecision="3" DBType="Number" />
<add NETType="int16" MinPrecision="4" MaxPrecision="5" DBType="Number" />
<add NETType="int32" MinPrecision="6" MaxPrecision="10" DBType="Number" />
<add NETType="int64" MinPrecision="11" MaxPrecision="19" DBType="Number" />
</edmNumberMapping>
</edmMappings>
</version>
</oracle.manageddataaccess.client>
My ultimate goal is to avoid modifying my POCO
May be you can declare your entity class as below to achieve what you need
public class Person
{
[Key]
public int Id { get; set; }
public int Active { get; set; }
[NotMapped]
public bool IsActive
{
get { return Convert.ToBoolean(Active); }
set { Active = Convert.ToInt32(value); }
}
}
Hope this helps.