コード例 #1
0
        public void Update(VideoAddDto dto)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <VideoEntity> bs
                    = new BaseService <VideoEntity>(ctx);

                bool exists = bs.GetAll().Any(u => u.Title == dto.Title && u.Id != dto.Id);

                if (exists)
                {
                    throw new ArgumentException("该视频已经存在:" + dto.Title);
                }
                var entity = dto.EntityMap();

                DbEntityEntry <VideoEntity> entry = ctx.Entry <VideoEntity>(entity);
                entry.State = EntityState.Modified;
                ctx.SaveChanges();

                //ctx.Videos.Attach(entity);
                //ctx.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);

                //ctx.SaveChanges();
            }
        }
コード例 #2
0
        public void Update(VideoDetailAddDto dto)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <VideoDetailEntity> bs
                    = new BaseService <VideoDetailEntity>(ctx);

                bool exists = bs.GetAll().Any(u => u.VideoDetailName == dto.VideoDetailName && u.Id != dto.Id);

                if (exists)
                {
                    throw new ArgumentException("该视频已经存在:" + dto.VideoDetailName);
                }
                var entity = dto.EntityMap();

                DbEntityEntry <VideoDetailEntity> entry = ctx.Entry <VideoDetailEntity>(entity);
                entry.State = EntityState.Modified;
                ctx.SaveChanges();
            }
        }