コード例 #1
0
        public T Update(T entity)
        {
            if (!Exists(entity.Id))
            {
                throw new NotSupportedException("Can not update inexist item");
            }
            var result = _mongoDBContext.Set <T>().SingleOrDefault(p => p.Id.Equals(entity.Id));

            if (result != null)
            {
                try
                {
                    _mongoDBContext.Entry(result).CurrentValues.SetValues(entity);
                    _mongoDBContext.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(entity);
        }