c# - Dapper with sql query dynamic parameters -
in asp.net web-api, getting error "ora-00936: missing expression" below code snippet. had tried many solutions did not overcome error. , want know how bind more 1 parameter dynamically. using oracle back-end , dapper orm.
string empid = json.empid; //'15rd005' var sql = @"select id_no,sno,reason,applieddate,case when leave_type = 0 'cl' when leave_type = 1 'el' when leave_type = 2 'sl' when leave_type = 3 'off' when leave_type = 4 'od-off' when leave_type = 5 'lop' when leave_type = 6 'optional' end leave_type, to_char(fromdate,'dd-mon-yyyy') f_date, to_char(todate,'dd-mon-yyyy') t_date, case when fromslot=0 'first-half' when fromslot=1 'second-half' when fromslot=2 'full-day' end from_slot, case when toslot=0 'first-half' when toslot=1 'second-half' when toslot=2 'full-day' end to_slot, applieddays app_days, case when actinact=0 , cancel_idno not null 'cancelled' when actinact=1 , auth_idno null 'pending' when actinact=0 , cancel_idno not null 'rejected' else 'authorised' end leave_status tleaves to_char(todate,'mm-yyyy') >= to_char(sysdate-30,'mm-yyyy') , to_char(todate,'mm-yyyy') <=to_char(sysdate,'mm-yyyy') , to_char(todate,'yyyy')=to_char(sysdate,'yyyy') , id_no @empid order sno"; try { using (oracleconnection db = new oracleconnection(constring)) { db.open(); var pastleavesreport = new pastleavesreportdto(); //3.present , last month lev status report list<pastleavesreportinfodto> pastleavesreportinfo = db.query<pastleavesreportinfodto>(sql, new { empid = empid }).tolist(); pastleavesreport.empid = ""; pastleavesreport.leaves = pastleavesreportinfo; return ok( new empleavesactionresponse(actionstatuscodes.pastleavesreportdatafound, "", pastleavesreport)); } } catch (exception exp) { return ok( new empleavesactionresponse(actionstatuscodes.serverexception, exp.message, null)); }
finally solved issue little change in code. @empid changed :empid, since oracle database supports dynamic parameters in way. , second question how handle multiple dynamic parameters using dappers dynamicparameters class shown below,
var parameters = new dictionary<string, object>(); parameters.add("id", empid); dynamicparameters dbparams = new dynamicparameters(); dbparams.adddynamicparams(parameters);
and can use in dapper shown in below code snippe, parameter query sample sql query.
dynamic result = db.query(query, dbparams);
Comments
Post a Comment