コード例 #1
0
ファイル: Manager.cs プロジェクト: Roman1696/HW_EF1
        public IEnumerable <Pupils> Insert()
        {
            var context = new PupilsContext();
            var pupils  = new List <Pupils>()
            {
                new Pupils()
                {
                    ID = 2, FirstName = "Vasya", LastName = "Pupkin", Phone = "0987543222"
                }
            };
            var school = new School()
            {
                Name = "KHNURE", Id = 2
            };
            var teacher = new ClassroomTeacher()
            {
                LastName = "MIchailuk", FirstName = "Ivan", Id = 2
            };


            context.Pupils.AddRange(pupils);
            context.Schools.Add(school);
            context.Teachers.Add(teacher);

            context.SaveChanges();

            return(context.Pupils.ToList());
        }
コード例 #2
0
ファイル: Manager.cs プロジェクト: Roman1696/HW_EF1
 public IEnumerable <Pupils> DeletePupilById(int id)
 {
     using (var context = new PupilsContext())
     {
         var pupils = context.Pupils.Where(o => o.ID == id).FirstOrDefault();
         context.Pupils.Remove(pupils);
         context.SaveChanges();
         return(context.Pupils.ToList());
     }
 }