Esempio n. 1
0
        private static void InsertNewCompany(String input)
        {
            using (var context = new Context())
            {
                var company = new Company()
                {
                    Name = input,
                };

                context.Companies.Add(company);

                context.SaveChanges();
            }
        }
Esempio n. 2
0
        private static void InsertPerson(String firstName, String lastName)
        {
            using (var context = new Context())
            {
                var person = new Person
                {
                    FirstName = firstName,
                    LastName = lastName

                };

                context.People.Add(person);

                context.SaveChanges();
            }
        }
Esempio n. 3
0
        private static void DeleteData()
        {
            using (var context = new Context())
            {

                var personId = 2;
                var person = context.People.Find(personId);
                if (person != null)
                {
                    context.People.Remove(person);
                    context.SaveChanges();
                }

            }
            QueryData();
        }
Esempio n. 4
0
 private static void UpdateData()
 {
     using (var context = new Context())
     {
         var savedPeople = context.People;
         if (savedPeople.Any())
         {
             var person = savedPeople.First();
             person.FirstName = "Johnny";
             person.LastName = "Benson";
             context.SaveChanges();
         }
     }
     QueryData();
 }