Bulk Update with SQL Server based on a list of primary keys
<p>I am processing data from a database with millions of rows. I am pulling a batch of 1000 items from the database and processing them without a problem. I am not loading the whole entity and I am just pulling down a few columns of data for the batch.</p>

<p>What I want to do is mark the 1000 rows as processed with a single SQL command.</p>

<p>Something like:</p>

<pre><code>UPDATE dbo.Clients 
SET HasProcessed = 1 
WHERE ClientID IN (...)
</code></pre>

<p>The ... is just a list of integers.</p>

<p><strong>Context</strong>:</p>

<ul>
<li>Azure SQL Server 2012 </li>
<li>Entity Framework 

<ul>
<li><code>Database.ExecuteSqlCommand</code></li>
</ul></li>
</ul>

<p><strong>Ideas</strong>:</p>

<p>I know I could build the command as a pure string, but this would mean not using any <code>SqlParameter</code>s and not benefiting from the query plan optimization.</p>

<p>Also, I found some information about table-valued parameters, but this requires creating a table type and some overhead which I would like to avoid. This is just a list of integers after all.</p>

<p><strong>Question</strong>:</p>

<p>Is there an easy (performant) way to do this that I am overlooking either with Entity Framework or <code>ExecuteSqlCommand</code>?</p>

<p>If not and using table-valued parameters is the best way, could you provide a complete example of how to convert an integer list into the simplest type and running that with the above query?</p>