static void Main(string[] args) { using (FluentModel dbContext = new FluentModel()) { // The method, which creates the database on the server. UpdateDatabase(); // Add a new customer. //Asegurado newCustomer = new Asegurado //{ // Nombre = "John Smith", // Apellidos = "*****@*****.**" //}; //dbContext.Add(newCustomer); // Commit changes to the database. dbContext.SaveChanges(); // Get the first customer using LINQ and modify it. //var customer = dbContext.Customers.FirstOrDefault(); // Commit changes to the database. //dbContext.SaveChanges(); // Use LINQ to retrieve a customer named John. // Delete the customer from the database. //// Commit changes to the database. //dbContext.SaveChanges(); } }
// The id parameter name should match the DataKeyNames value set on the control public void fwNuevaPersona_UpdateItem(int PersonaId) { try { using (FluentModel db = new FluentModel()) { Inmobiliaria.Dto.Persona usuario = db.Personas.Single(persona => persona.PersonaId == PersonaId); // Load the item here, e.g. item = MyDataLayer.Find(id); if (usuario == null) { // The item wasn't found ModelState.AddModelError("", String.Format("Item with id {0} was not found", PersonaId)); return; } TryUpdateModel(usuario); if (ModelState.IsValid) { db.SaveChanges(); } else { var errors = ModelState.Values.SelectMany(v => v.Errors); } } } catch (Exception ex) { throw; } }
public void TestMethod2() { using (FluentModel db = new FluentModel()) { IList<Persona> personas = db.Personas.ToList(); db.SaveChanges(); Assert.IsNotNull(personas); } }
public void fwNuevaPersona_InsertItem() { try { Persona nuevoUsuario = new Persona(); TryUpdateModel(nuevoUsuario); if (ModelState.IsValid) { using (FluentModel db = new FluentModel()) { db.Add(nuevoUsuario); db.SaveChanges(); } } } catch (Exception ex) { throw; } }