我在PostgreSQL中有一个函数,我想通过dapper执行它,但它会抛出一个错误,说明该函数不存在:
我在postgres中的功能:
CREATE OR REPLACE FUNCTION wpv.production_availability_sum_avg(
IN dtfrom date,
IN dtto date,
IN supervisor text,
IN reginalmanager text,
IN serviceunder text)
RETURNS TABLE(production numeric, turbine_name text, wind_speed double precision, availability double precision, power_curve_quality double precision) AS
$BODY$declare
begin
return query
select sum(m_energy_prod::numeric) Production,f.turbine_name::text, round(avg(m_wind_speed), 2) wind_speed, round(avg(m_corrected_av), 2) availability,
round(avg(t1.power_curve_quality), 2) power_curve_quality
from wpv.v_statistics_daily v1
left outer join wh.t_statistics_daily_ext t1 on t1.m_turbine_id = v1.m_turbine_id and t1.m_date=v1.m_date
JOIN wpv.v_master_data_turbine f on (f.m_turbine_id=v1.m_turbine_id)
JOIN zd.t_users g on(g.user_id=f.pv_person_resp_id)
where (v1.m_date between dtfrom and dtto)
and
f.m_turbine_supervisor like serviceunder
and g.user_name Like(reginalmanager)
and f.service_under Like(serviceunder) end)
group by 2
order by 4 ASC
limit 20;
end;$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;
ALTER FUNCTION wpv.production_availability_sum_avg(date, date, text, text, text)
OWNER TO postgres;
这是我的代码
var t = new {dtfrom=Convert.ToDateTime( "03/05/2018") ,dtto= Convert.ToDateTime( "04/05/2018"),supervisor="%",regionalmanager="%",serviceunder="%" };
DynamicParameters p = new DynamicParameters();
p.Add("@dtfrom", "03/05/2018",DbType.Date,ParameterDirection.Input);
p.Add("@dtto", "04/05/2018",DbType.Date, ParameterDirection.Input);
p.Add("@supervisor", "%",DbType.String, ParameterDirection.Input);
p.Add("@regionalmanager", "%",DbType.String, ParameterDirection.Input);
p.Add("@serviceunder", "%",DbType.String, ParameterDirection.Input);
var s = connection.Query<DataTable>("wpv.production_availability_sum_avg", p,
commandType: CommandType.StoredProcedure);
最后一部分,我想执行查询我得到错误,功能不存在,但我相信它存在,我在postgres测试,它的工作