예제 #1
0
파일: Program.cs 프로젝트: khuynh10/hwk7
 private static void QueryCompanies()
 {
     using (var context = new Context())
     {
         foreach (var company in context.Companies)
         {
             Console.WriteLine("C.id: {0}, Company Name: {1}",
                 company.CompanyId, company.Name);
         }
     }
 }
예제 #2
0
파일: Program.cs 프로젝트: khuynh10/hwk7
        private static void InsertNewCompany(String input)
        {
            using (var context = new Context())
            {
                var company = new Company()
                {
                    Name = input,
                };

                context.Companies.Add(company);

                context.SaveChanges();
            }
        }
예제 #3
0
파일: Program.cs 프로젝트: khuynh10/hwk7
        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();
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: khuynh10/hwk7
        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();
        }
예제 #5
0
파일: Program.cs 프로젝트: khuynh10/hwk7
 private static void QueryData()
 {
     using (var context = new Context())
     {
         var savedPeople = context.People;
         foreach (var person in savedPeople)
         {
             Console.WriteLine("id: {0}, Firstname: {1}, Lastname: {2}",
               person.PersonId, person.FirstName, person.LastName);
         }
     }
 }
예제 #6
0
파일: Program.cs 프로젝트: khuynh10/hwk7
 private static void VerifyDatabaseExists()
 {
     using (var context = new Context())
     {
         context.Database.CreateIfNotExists();
     }
 }
예제 #7
0
파일: Program.cs 프로젝트: khuynh10/hwk7
 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();
 }