stored procedures - ServiceStack MARS (Multiple Active Result Sets) using ORMLite and Output Parameters -


servicestack ormlite great, i've typically steered clear of orm mentality preferring build databases makes sense build databases instead of 1:1 class model. said, there couple of things seem running difficulty around, i'm it's ignorance shining through.

first:

is there way manage multiple result sets using ormlite? know 1 can use querymultiple method using dapper, whatever reason i'm having bear of time figuring out how use built-in dapper implementation of servicestack.

second:

is there way using ormlite return output parameters within stored procedure call?

ideally, i'd steer clear of mars , output parameters , ideally i'd live in ideal world :)

i'm using .net framework 4.5, sql server 2008 r2 , servicestack 3.9.46.

it turns out quite simple (provided know magic make happen).

based on documentation , seemingly misleading post indicating dapper "included" in razor assumed when implied dapper "built-in" part of included libraries.

laugh if will, of aren't enlightened, i'm going outline how make dapper extensions show up. here's magic.

using package manager console execute following:

install-package servicestack install-package dapper 

add following using statements (c#) service:

using servicestack.ormlite; using dapper; 

now, when leverage db object ormlite , dapper methods there.

to output parameter simple as:

var p = new dynamicparameters();  p.add("@param1", request.stuff1); p.add("@param2", request.stuff2); p.add("@param3", dbtype: dbtype.int32, direction: parameterdirection.output);  db.execute("schema.sp_stored_proc_name", p, commandtype: commandtype.storedprocedure);  response.outputstuff = p.get<int>("@param3"); 

in order manage mars (assume have sp returns 2 result sets , output param):

p.add("@param1", request.stuff1); p.add("@param2", request.stuff2); p.add("@param3", dbtype: dbtype.int32, direction: parameterdirection.output);  var mars = db.querymultiple("schema.sp_stored_proc_name", p, commandtype: commandtype.storedprocedure);  //firstset contains first result set var firstset = mars.read().tolist(); //secondset contains second result set var secondset = mars.read().tolist();  response.outputstuff = p.get<int>("param3"); 

it's beautifully simple, once know magic :)

here's much more complicated example.

hopefully helps else out , saves them bit of time.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -