c# - Performing Inserts and Updates with Dapper -
i interested in using dapper - can tell supports query , execute. not see dapper includes way of inserting , updating objects.
given our project (most projects?) need inserts , updates, best practice doing inserts , updates alongside dapper?
preferably not have resort ado.net method of parameter building, etc.
the best answer can come @ point use linqtosql inserts , updates. there better answer?
we looking @ building few helpers, still deciding on apis , if goes in core or not. see: http://code.google.com/p/dapper-dot-net/issues/detail?id=6 progress.
in mean time can following
val = "my value"; cnn.execute("insert table(val) values(@val)", new {val}); cnn.execute("update table set val = @val id = @id", new {val, id = 1});
etcetera
see blog post: that annoying insert problem
update
as pointed out in comments, there several extensions available in dapper.contrib project in form of these idbconnection
extension methods:
t get<t>(id); ienumerable<t> getall<t>(); int insert<t>(t obj); int insert<t>(enumerable<t> list); bool update<t>(t obj); bool update<t>(enumerable<t> list); bool delete<t>(t obj); bool delete<t>(enumerable<t> list); bool deleteall<t>();
Comments
Post a Comment