c# - Updating an Informix database over ODBC with an object using Dapper -
i'm trying figure out if there's way update object in 1 shot dapper rather having write out every variable/field alignment. here's illustration of i'm doing now, explicitly spell out each field:
public string updateattributes(list<itemattribute> attributeslist) { seek { using (ifxconnection con = new ifxconnection(webconfigurationmanager.appsettings["lokiconn"].tostring())) { con.open(); foreach (itemattribute item in attributeslist) { con.execute("update oe_cnvwrk set cwr_response = ?, cwr_uom = ? cwr_genero = ? , cwr_line = ?", new { cwr_response = item.cwr_response, cwr_uom = item.cwr_uom, cwr_genero = item.cwr_genero, cwr_line = item.cwr_line }); } con.close(); homecoming "success"; } } grab (exception x) { homecoming x.tostring(); } }
is there way skip spelling out each variable , reference object? or improve way approach period? dapper allows dynamically creating object query, , populating values of pre-defined object, updating existing object i'm not finding documentation or examples. larger object becomes bit of pain, maintenance if table , object need changed.
this might work:
using (ifxconnection con = new ifxconnection(webconfigurationmanager.appsettings["lokiconn"].tostring())) { con.execute("update oe_cnvwrk set cwr_response = ?cwr_response?, cwr_uom = ?cwr_uom? cwr_genero = ?cwr_genero? , cwr_line = ?cwr_line?", attributeslist); homecoming "success"; }
changes:
no need open/close connection passes sequence directly; no need loop uses special dapper?foo?
syntax, maps named members available info positional sql; re-written utilize positional ?
sql, adding expected parameters in expected order c# dapper
No comments:
Post a Comment