title: Swap two values in a SQL Server table
body: <p>I have a table with two columns, Name and Priority. Let's assume the current data is (A,1)(B,2)(C,3)(D,4).</p>
  
  <p>Now from the UI, I'm editing D. That is I'm updating D's priority to 2. Now I should update D's priority as 2 and set B's priority to 4. I'm swapping the priorities of D and B. How do I do this? My project uses Entity framework. This is how I'm currently doing,</p>
  
  <pre><code>public void Swap(InputObject input)
          {
              NamePriority prio = context.NamePriorities.Where(w =&gt; w.Name == input.Name.FirstOrDefault();
              NamePriority prioToSwap = context.NamePriorities.Where(w.Priority == input.Priority).FirstOrDefault();
              prioToSwap.Priority = prio.Priority;
              context.SaveChanges();
              prio.Priority = input.Priority;
              context.SaveChanges();
          }
  </code></pre>
  
  <p>Is there a simpler or cleaner way to do this like using a LINQ lambda expression or something?</p>