title: Ignore null values patch ef core
body: <p>Updating records using EF, but it is not updating accordingly. I just want to update only the fields that are not null and modified. In previous I'm doing like this:</p>
  <pre><code>_context.Attach(exist).CurrentValues.SetValues(t);
  </code></pre>
  <p>which it will update all the fields and I don't want that.</p>
  <p>Is there anything that I missed on my code?</p>
  <pre><code>    public virtual async Task&lt;T&gt; UpdateAsync(T t, object key)
      {
          if (t == null)
              return null;
              
          T exist = await _context.Set&lt;T&gt;().FindAsync(key);
  
          if (exist != null)
          { 
              // _context.Attach(exist).CurrentValues.SetValues(t); 
              _context.Attach(exist); 
  
              var entry = _context.Entry(t);
  
              Type type = typeof(T);
              PropertyInfo[] properties = type.GetProperties();
  
              foreach (PropertyInfo property in properties)
              {
                  if (property.GetValue(t, null) == null)
                  {
                      entry.Property(property.Name).IsModified = false;
                  }
              }
  
              // _context.Attach(exist).CurrentValues.SetValues(t);                  
              await _context.SaveChangesAsync();
          }
  
          return exist;
      }
  </code></pre>