public void setDetalleFactura() { try { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { using (agrosysEntitiesFull facturaEntidad = new agrosysEntitiesFull()) { detalle_factura objDetalleFactura = new detalle_factura(); objDetalleFactura.cantidad = Convert.ToInt32(ds.Tables[0].Rows[i]["cantidad"]); objDetalleFactura.sub_total = ds.Tables[0].Rows[i]["subTotal"].ToString(); objDetalleFactura.factura_id_factura = Convert.ToInt32(ds.Tables[0].Rows[i]["facturaID"]); objDetalleFactura.producto_id_producto = Convert.ToInt32(ds.Tables[0].Rows[i]["productoID"]); facturaEntidad.detalle_factura.Add(objDetalleFactura); facturaEntidad.SaveChanges(); } } } catch (Exception) { throw new Exception("Hay un problema al guardar la factura, por favor intente de nuevo."); } }