/// <summary>
        ///     The perform database operations.
        /// </summary>
        public static void PerformDatabaseOperations()
        {
            using (var db = new PersonDbContext())
            {
                var person = new Person { FirstName = "Nadege", LastName = "Deroussen", BirthDate = DateTime.Now };

                db.Persons.Add(person);
                db.SaveChanges();
            }
        }
        /// <summary>
        ///     The perform database operations.
        /// </summary>
        public static void PerformDatabaseOperations()
        {
            using (var db = new PersonDbContext())
            {
                Console.WriteLine();
                Console.WriteLine("All objects in database:");

                foreach (var cars in db.Cars)

                {
                    Console.WriteLine(" -{0}", cars.Make);
                    Console.WriteLine(" -{0}", cars.Model);
                    Console.WriteLine(" -{0}", cars.Country);
                    Console.WriteLine(" -{0}", cars.CarId);
                }

                var car = new Car
                {
                    CarId   = 1112,
                    Model   = "Mercedes",
                    Make    = "E-class",
                    Country = "Germany",
                    Year    = DateTime.Now
                };
                db.Cars.Add(car);

                var count = db.SaveChanges();
                Console.WriteLine("{0} car saved to database", count);


                foreach (var persons in db.Persons)

                {
                    Console.WriteLine(" -{0}", persons.FirstName);
                    Console.WriteLine(" -{0}", persons.LastName);
                    Console.WriteLine(" -{0}", persons.City);
                    Console.WriteLine(" -{0}", persons.PersonId);
                }

                var person = new Person
                {
                    PersonId  = 1111,
                    FirstName = "Britney",
                    LastName  = "Spears",
                    City      = "New York",
                    BirthDate = DateTime.Now
                };

                db.Persons.Add(person);
                var count1 = db.SaveChanges();
                Console.WriteLine("{0} person saved to database", count1);
            }
        }
Esempio n. 3
0
        /// <summary>
        ///     The perform database operations.
        /// </summary>
        public static void PerformDatabaseOperations()
        {
            using (var db = new PersonDbContext())
            {
                var person = new Person {
                    FirstName = "Nadege", LastName = "Deroussen", BirthDate = DateTime.Now
                };

                db.Persons.Add(person);
                db.SaveChanges();
            }
        }
Esempio n. 4
0
        /// <summary>
        ///     The perform database operations.
        /// </summary>
        public static void PerformDatabaseOperations()
        {
            using (var db = new PersonDbContext())
            {
                var person = new Person
                {
                    FirstName = "Mohit",
                    LastName  = "Mehndiratta",
                    BirthDate = DateTime.Now
                };

                db.Persons.Add(person);
                db.SaveChanges();
            }
        }