title: Should I check if a row exists before deletion?
body: <p>I'm using Mssql as the db and EF4 as the ORM/DAL.<br>
  My question is about the following code:</p>
  
  <pre><code>public static void DeleteBuilding(int buildingId, int countryId)
  {
      PlayerBuilding playerBuilding = new PlayerBuilding()
      {
          CountryID = countryId,
          BuildingID = buildingId
      };
      Entities.PlayerBuildings.Attach(playerBuilding);
      Entities.PlayerBuildings.DeleteObject(playerBuilding);
      Entities.SaveChanges();
  }
  </code></pre>
  
  <p>If the row exists this works very well, <strong>if not</strong> I get an exception(<em>Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.</em>)<br>
  Should I make a round trip to the database to check if the row exists like this:</p>
  
  <pre><code>public static void DeleteBuilding(int buildingId, int countryId)
  {
      PlayerBuilding playerBuilding = (from p in Entities.PlayerBuildings
                                       where p.BuildingID == buildingId &amp;&amp; p.CountryID == countryId
                                       select p).FirstOrDefault();
      if (playerBuilding != null)
      {
          Entities.PlayerBuildings.DeleteObject(playerBuilding);
          Entities.SaveChanges();
      }
  }
  </code></pre>
  
  <p>I think that extra round trip is kinda unnecessary because without the EF, with plain SQL I could simply delete the row with a single DELETE command.    </p>
  
  <p>What would be a better practice?</p>