Example #1
0
        static void Main(string[] args)
        {
            try
            {
                ManageDatabase();

                using (var ctx = new Models.PersonDBContext())
                {
                    var person = new Models.Person();
                    person.PersonName = "Name 2";
                    person.Age        = 30;
                    person.Gender     = "Female";

                    ctx.Persons.Add(person);
                    ctx.SaveChanges();

                    Console.WriteLine("added person");

                    foreach (var p in ctx.Persons.ToList())
                    {
                        Console.WriteLine($"{p.PersonName} {p.Age} {p.Gender}");
                    }
                };
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");
            try
            {
                ManageDatabase();
                using (var ctx = new Models.PersonDBContext())
                {
                    var person = new Models.Person()
                    {
                        //PersonID = 1,
                        PersonName = "Pankaj",
                        Gender     = "M",
                        Age        = 36
                    };

                    ctx.Persons.Add(person);
                    ctx.SaveChanges();

                    Console.WriteLine("Added Person");

                    foreach (var p in ctx.Persons.ToList())
                    {
                        Console.WriteLine($"{p.PersonID} {p.PersonName} {p.Gender} {p.Age}");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
Example #3
0
 static void ManageDatabase()
 {
     using (var ctx = new Models.PersonDBContext())
     {
         ctx.Database.EnsureDeleted();
         ctx.Database.EnsureCreated();
     }
 }