Dapper and DynamicParameter() -
i looking through code , unable read it. tried find material , examples unable find specific or documentation me understand issue. can read me code , if there documentation read it.
at first question why need use dynamicparameter() object of dapper. not sure => means.
public void validrecord(string filename, string rawcontent, int userid) { run(conn => conn.execute("[dbo].[storedproc_getdone]" , new dynamicparameters (new dictionary<string, object> { {"filename", filename}, {"rowcontent", rawcontent}, {"usercreated", userid}, }), commandtype.storedprocedure)); }
run not part of dapper, => in c# used create lambda expression, in case expect action<dbconnection>, i.e. guess run looks lot this:
run(action<dbconnection> action) { using(var conn = createconnection()) { conn.open(); action(conn); } } i.e. "i'm going give connection; want it?" - in case choosing execute stored procedure.
now, worth noting in example there no benefit in using dynamicparameters, since information known - use:
run(conn => conn.execute("[dbo].[storedproc_getdone]", new { filename, rawcontent, usercreated = userid }, commandtype.storedprocedure)); which work well. in answer "why need use dynamicparameter - you don't in scenario. however, in cases might - if building sql on fly manually, example:
if(name != null) { sql.append("and name = @name "); args.add("name", name); }
Comments
Post a Comment