public DepartmentDTO ToDTO(tb_Department te)
        {
            DepartmentDTO tdto = new DepartmentDTO();

            tdto.Sid  = te.Sid.Value;
            tdto.Name = te.Department;
            return(tdto);
        }
        public tb_Department ToEntity(DepartmentDTO dto)
        {
            tb_Department te = new tb_Department();

            te.Sid        = dto.Sid;
            te.Department = dto.Name;
            return(te);
        }
Beispiel #3
0
        public void Save(DepartmentDTO dto)
        {
            //using (var dbContextTransaction = context.Database.BeginTransaction())
            //context.SaveChanges();
            //dbContextTransaction.Commit();
            //dbContextTransaction.Rollback();
            //http://codethug.com/2016/02/19/Entity-Framework-Cache-Busting/
            tb_Department te = transformer.ToEntity(dto);
            tb_Department t;

            using (MyDbContext context = new MyDbContext())
            {
                //var stuff = context.MyDepartmentSet.Include(E => E.Comments.FirstOrDefault()).ToList();
                //var stuff = context.MyDepartmentSet.Include(d => d.Comments).Select(d => new { Department = d, HasChild = d.Comments.FirstOrDefault() }).ToList();

                var stuff = context.MyDepartmentSet.Include(d => d.Comments).Select(d => new { Department = d, HasChild = d.Comments.Any() }).ToList();
                context.MyDepartmentSet.AddOrUpdate(p => new { p.Department }, te);
                //context.MyDepartmentSet.Add(te);
                context.SaveChanges();

                tb_Department_Comment c = new tb_Department_Comment()
                {
                    Comment = te.Department
                };
                te.Comments.Add(c);

                context.SaveChanges();

                t = context.MyDepartmentSet
                    .Where(d => d.Sid.Value == 1876)
                    .AsNoTracking()
                    .FirstOrDefault();

                /*
                 * tb_Department_Comment newC = new tb_Department_Comment() { Department_SID = te.Sid.Value, Comment = "hi" };
                 * context.MyCommentSet.Add(newC);
                 * context.SaveChanges();
                 */
                var loadedComment  = context.MyCommentSet.Where(cc => cc.Sid.Value == 1).SingleOrDefault();
                var loadedComment2 = context.MyCommentSet.Where(cc => cc.Sid.Value == 2).SingleOrDefault();
            }
            Console.Out.WriteLine("save was called");
        }