public void ExecuteEntity() { XmlDocument xDocWriter = new XmlDocument(); xDocWriter.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement xml = xDocWriter.CreateElement("xml"); xDocWriter.AppendChild(xml); XmlElement alugueres = xDocWriter.CreateElement("alugueres"); Console.WriteLine("Insert begin date:"); string begin = Console.ReadLine(); DateTime begin_date = Convert.ToDateTime(begin); Console.WriteLine("Insert end date:"); string end = Console.ReadLine(); DateTime end_date = Convert.ToDateTime(end); alugueres.SetAttribute("dataInicio", begin_date.Date.ToString()); alugueres.SetAttribute("dataFim", end_date.Date.ToString()); xml.AppendChild(alugueres); using (var ctx = new AenimaEntities()) { var rents = ctx.Rents.Where(r => r.date_time >= begin_date && r.end_date <= end_date); foreach (var q in rents) { XmlElement aluguer = xDocWriter.CreateElement("aluguer"); aluguer.SetAttribute("id", q.serial_nr.ToString()); aluguer.SetAttribute("tipo", q.rent_time.ToString() + "m"); XmlElement client = xDocWriter.CreateElement("cliente"); client.InnerText = q.client_code.ToString(); XmlElement equipment = xDocWriter.CreateElement("equipamento"); equipment.InnerText = q.equipment_code.ToString(); aluguer.AppendChild(client); aluguer.AppendChild(equipment); alugueres.AppendChild(aluguer); } } Console.WriteLine("XML sucessfully exported!"); xDocWriter.Save("ExportedResultEF.xml"); OpenFile("notepad.exe", "ExportedResultEF.xml"); }
public void ExecuteEntity() { int rentTime, rentPrice, equipCode, empNumber, clientCode; List <int> prms = new List <int>(); prms = InsertRentInfo(prms); try { rentTime = prms[0]; rentPrice = prms[1]; equipCode = prms[2]; empNumber = prms[3]; clientCode = prms[4]; } catch (FormatException) { Console.WriteLine("Some parameters were wrong..."); return; } var serial_nr = new ObjectParameter("serial_nr", typeof(Int32)); using (var ctx = new AenimaEntities()) { try { ctx.InsertRent(rentTime, rentPrice, equipCode, empNumber, clientCode, serial_nr); ctx.SaveChanges(); }catch (Exception e) { Console.WriteLine(e.InnerException.Message); return; } } Console.WriteLine("Inserted Rent with id {0}", serial_nr.Value); }