title: Entity Framework - Only update values that are not null
body: <p>This is a bit of a new one for me.  I've been asked to write an ETL program that loads two datasets into the same table.  Dataset #1 is complete and contains all the data for the table.  Dataset#2, however, only contains <em>changes</em> that need to be overlaid onto the first dataset.  Observe:</p>
  
  <p>// Dataset #1: Widgets Table</p>
  
  <pre><code>+----+------+------+------+------+
  | ID | COL1 | COL2 | COL3 | COL4 |
  +----+------+------+------+------+
  | 1  | abcd | abcd | abcd | abcd |
  +----+------+------+------+------+
  | 2  | abcd | abcd | abcd | abcd |
  +----+------+------+------+------+
  </code></pre>
  
  <p>// Dataset #2: Widgets_Changes Table</p>
  
  <pre><code>+----+------+------+------+------+
  | ID | COL1 | COL2 | COL3 | COL4 |
  +----+------+------+------+------+
  | 1  |      | efgh |      | ijkl |
  +----+------+------+------+------+
  | 2  | mnop |      | qrst |      |
  +----+------+------+------+------+
  </code></pre>
  
  <p>// The Anticipated Result: Widgets with all Changes</p>
  
  <pre><code>+----+------+------+------+------+
  | ID | COL1 | COL2 | COL3 | COL4 |
  +----+------+------+------+------+
  | 1  | abcd | efgj | abcd | ijkl |
  +----+------+------+------+------+
  | 2  | mnop | abcd | qrst | abcd |
  +----+------+------+------+------+
  </code></pre>
  
  <p>The obvious approach (that I'm trying to avoid) is to pull each widget out of the first table and do a property-by-property comparison:</p>
  
  <pre><code>// Simplified example:
  using ( var db = new MyEntityDatabase() ){
  
     var widget      = from p in db.Widgets select p where p.ID == 1;
     var widget_diff = from p in db.Widgets_Changes select p where p.ID == 1
  
     widget.COL1 = widget_diff.COL1 ?? widget.COL1;
     widget.COL2 = widget_diff.COL2 ?? widget.COL2;
     widget.COL3 = widget_diff.COL3 ?? widget.COL3;
     // ...etc
  
     db.saveChanges();
  }
  </code></pre>
  
  <p>However, there are over 200 fields in this particular dataset, with more files incoming that adhere to this same methodology (complete dataset accompanied by diff dataset) but have a different schema entirely.  Obviously, I'd rather have something portable that I can just run the files through instead of having to hard-code property-by-property comparisons for each dataset.</p>
  
  <p>Is there a way I can iterate through the properties of both objects and update values that aren't null?</p>