title: Entity Framework Bulk Merge
body: <p>I am trying to use Entity Framework to perform a merge operation. I have tried using the naive approach of retrieving the records and then doing the logic in the code, but it is very slow.</p>
  
  <p>I have also looked into using the Bulk Insert library as discussed <a href="https://stackoverflow.com/questions/6107206/improving-bulk-insert-performance-in-entity-framework">here</a>, but it only supports bulk inserts. </p>
  
  <p>So far my work-around has been to create a stored procedure, define a Table Value Type for my table, dynamically generate the input datatable using reflection, and then execute the stored procedure.</p>
  
  <p>What this means, of course, is that every time my table definition changes, I now have to go in and change the stored procedure code and the table value type as well.</p>
  
  <p>Is there any better way to do this? If I could dynamically generate column definitions from Entity Framework that would already help a lot.</p>
  
  <p>EDIT: I am referring to T-SQL Merge: <a href="http://msdn.microsoft.com/en-us/library/bb510625.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/bb510625.aspx</a></p>