コード例 #1
0
        public async Task ApplyPatchAsync <TEntity>(TEntity entityUpdated) where TEntity : class
        {
            if (entityUpdated == null)
            {
                throw new ArgumentNullException($"{nameof(entityUpdated)}", $"{nameof(entityUpdated)} cannot be null.");
            }

            var properties = entityUpdated.GetFilledProperties();

            _coditoContext.Attach(entityUpdated);

            foreach (var property in properties)
            {
                if (!_coditoContext.Entry(entityUpdated).Property(property).Metadata.IsKey())
                {
                    _coditoContext.Entry(entityUpdated).Property(property).IsModified = true;
                }
            }

            await _coditoContext.SaveChangesAsync();
        }