orm - Using Dapper inside a Static Class -
i'm building synchronization system. now, need insert executed stored procedure table. solution add static class , have dapper run inside of it. in theory static class/functions okay use when not changing object state case. thought careful , ask guys on think. cause problem down line?
public static class model { public static int executestoreprocedure(string name, string xml,bool sync=true) { using (sqlconnection con = new sqlconnection(strings.connectionstring)) { //pre var result = con.query<int>(name, new { xml = xml }, commandtype: commandtype.storedprocedure).firstordefault(); //post // insert new table goes here } } }
you're not accessing shared state, , not relying on static connection, sure - that'll work. there lots of ways of implementing data access, different trade-offs, should work fine. don't fall "java trap" of assuming need 16 layers of abstraction (including isomething, abstractsomething, 2 somethings, abstractsomethingfactory , somethingfactoryfactory 200 lines of configuration in obscure markup language) simple.
Comments
Post a Comment