In my asp.net project I use dapper for getting data from an Oracle database. I have an sql request like this:
select SUM(( pt.end_date - pt.start_date ) * 24 ) time_coacsh
,SUM(( pt.end_date - pt.start_date ) * 24 )/COUNT(rc.reg_coach_id) oborot_coacsh
from ...
and a model with only these properties:
[Column("time_coacsh")]
public Double TimeCoacsh { get; set; }
[Column("oborot_coacsh")]
public Double OborotCoacsh { get; set; }
I am trying to get a list of objects through the following method:
public IEnumerable<TModel> Query<TModel>(string sql, object paramsSql = null)
{
SqlMapper.SetTypeMap(typeof(TModel), new CustomPropertyTypeMap(typeof(TModel), BaseParamMappings.SelectProperty));
return SqlMapper.Query<TModel>(_db, new CommandDefinition(sql, paramsSql, null, null, CommandType.Text)).ToList();
}
However I get this error:
Error parsing column 0 (TIME_COACSH=null)
If I execute the sql request in oracle I will get needed data without some null
values.
In the model I tried to use Float, Decimal, Double, but I get the same error.
I solved this problem.
fields time_coacsh
and oborot_coacsh
were equal to values like 13,333333333333333333333333333338
that is, they had about 40 decimal places.
i changed sql request to
select round( SUM( ( pt.end_date - pt.start_date ) * 24 ),2 ) time_coacsh
,round (SUM( ( pt.end_date - pt.start_date ) * 24 )/COUNT( rc.reg_coach_id ), 2) oborot_coacsh
and in model use Decimal
type for these fields
PS: Dapper support Column
attribute