asp.net - Add custom key on C# Aspnet WebApi result object -
asp.net - Add custom key on C# Aspnet WebApi result object -
i have create asp.net webapi.
i have structured objects
[serializable()] public partial class orderlist { [key] public string clienteid; public list<ordine> ordini; } public class ordine { [key] public string codord; public string stato; public string pagamento; public list<riga> righe; } public class riga { public string articolo; public string quantita; public string listino; }
and populate object code:
public ienumerable<orderlist> get() { list<orderlist> opdatalist = new list<orderlist>(); string sqlclienti = " select codice clienti "; string connstr = configurationmanager.connectionstrings["sqlserver"].connectionstring; using (sqlconnection conn = new sqlconnection(connstr)) { using (sqlcommand cmd = new sqlcommand(sqlclienti, conn)) { conn.open(); using (sqldatareader app_dr = cmd.executereader()) { while(app_dr.read()) { orderlist itemtoadd = new orderlist(); itemtoadd.clienteid = app_dr["codice"].tostring(); string sqlordine = " select * order "; sqlordine += " codcli = '" + app_dr["codice"].tostring() + "'"; list<ordine> orderlisttoadd = new list<ordine>(); using (sqlconnection conn_1 = new sqlconnection(connstr)) { using (sqlcommand cmd_1 = new sqlcommand(sqlordine, conn_1)) { conn_1.open(); using (sqldatareader app_dr_1 = cmd_1.executereader()) { while (app_dr_1.read()) { ordine ordertoadd = new ordine(); ordertoadd.codord = app_dr_1["codord"].tostring(); ordertoadd.stato = app_dr_1["stato"].tostring(); list<riga> righelisttoadd = new list<riga>(); string sqldettaglio = " select rigord bi.nummxl='" + app_dr_1["numfat"].tostring() + "' , bi.datmxl='" + app_dr_1["datmxl"].tostring() + "' "; using (sqlconnection conn_2 = new sqlconnection(connstr)) { using (sqlcommand cmd_2 = new sqlcommand(sqldettaglio, conn_2)) { conn_2.open(); using (sqldatareader app_dr_2 = cmd_2.executereader()) { while (app_dr_2.read()) { riga rigatoadd = new riga(); rigatoadd.articolo = app_dr_2["articolo"].tostring(); rigatoadd.listino = app_dr_2["listino1"].tostring(); rigatoadd.quantita = app_dr_2["quantita"].tostring(); righelisttoadd.add(rigatoadd); } } conn_2.close(); } } ordertoadd.righe = righelisttoadd; orderlisttoadd.add(ordertoadd); } } conn_1.close(); } } itemtoadd.ordini = orderlisttoadd; opdatalist.add(itemtoadd); } } conn.close(); } } homecoming opdatalist; }
all work fine , have result
[ { "clienteid": "3458", "ordini": [ { "codord": "ow_285", "stato": "evaso", "pagamento": "contrassegno al corriere", "righe": [ { "articolo": "5114-21", "quantita": "6", "listino": "2,8" }, { "articolo": "t1057", "quantita": "6", "listino": "12,8" } ] } ] }, { "clienteid": "1297", "ordini": [ { "codord": "oc_1/2985", "stato": "evaso", "pagamento": "contrassegno al corriere", "righe": [ { "articolo": "b892vr", "quantita": "12", "listino": "2,5" }, { "articolo": "b895vr", "quantita": "12", "listino": "3,2" } ] } ] } ]
but result this:
{ "1297": { "clienteid": "1297", "ordini": { "oc_1/2985": { "codord": "oc_1/2985", "stato": "evaso", "pagamento": "contrassegno al corriere", "righe": [ { "articolo": "b892vr", "quantita": "12", "listino": "2,5" }, { "articolo": "b895vr", "quantita": "12", "listino": "3,2" } ] } } }, "3458": { "clienteid": "3458", "ordini": { "ow_285": { "codord": "ow_285", "stato": "evaso", "pagamento": "contrassegno al corriere", "righe": [ { "articolo": "5114-21", "quantita": "6", "listino": "2,8" }, { "articolo": "t1057", "quantita": "6", "listino": "12,8" } ] } } } }
how can add together object key on structure?
c# asp.net json web-api asp.net-web-api2
Comments
Post a Comment