Exemple #1
0
        private static void updatePerson()
        {
            // var person = new Person { Forename = "Paul", Surname = "Kane", NoOfDaysLeft = 30 };
            var person2 = new Person {
                Forename = "Sam", Surname = "Kane", NoOfDaysLeft = 20
            };

            Person person;

            using (var context = new HCISContext())
            {
                person = context.Persons.FirstOrDefault();
            }

            person.Surname = "Test";


            using (var context = new HCISContext())
            {
                context.Persons.Attach(person);
                context.Entry(person).State = EntityState.Modified;

                context.Database.Log = Console.WriteLine;
                context.SaveChanges();
            }
        }
Exemple #2
0
        private static void removePerson2()
        {
            //use a stored procedure
            using (var context = new HCISContext())
            {
                var person = context.Persons.FirstOrDefault();

                context.Entry(person).State = EntityState.Deleted;

                int key = 1;
                context.Database.ExecuteSqlCommand("exec deletePerson {0}", key);

                context.SaveChanges();
            }
        }
Exemple #3
0
        private static void addSomeLeave()
        {
            using (var context = new HCISContext())
            {
                context.Database.Log = Console.WriteLine;

                var person = context.Persons.FirstOrDefault();

                var leave1 = new Leave {
                    FromDate = new DateTime(2019, 1, 1), ToDate = new DateTime(2019, 1, 3), NoWorkingDays = 1, LeaveTypeId = LeaveType.AnnualLeave
                };
                var leave2 = new Leave {
                    FromDate = new DateTime(2019, 3, 1), ToDate = new DateTime(2019, 3, 3), NoWorkingDays = 1, LeaveTypeId = LeaveType.AnnualLeave
                };

                person.LeaveItems.Add(leave1);
                person.LeaveItems.Add(leave2);

                context.SaveChanges();
            }
        }
Exemple #4
0
        private static void insertPerson()
        {
            var person = new Person {
                Forename = "Paul", Surname = "Kane", NoOfDaysLeft = 30
            };
            var person2 = new Person {
                Forename = "Sam", Surname = "Kane", NoOfDaysLeft = 20
            };



            using (var context = new HCISContext())
            {
                context.Database.Log = Console.WriteLine;
                //context.Persons.Add(person);
                context.Persons.AddRange(new List <Person> {
                    person, person2
                });


                context.SaveChanges();
            }
        }