title: Why is this LINQ query returning null when a match exists?
body: <p>I have the following LINQ query, in a server-side rest API, but it is not matching existing records:</p>
  
  <pre><code>var existing = (from p in context.GameAction
                  where p.GameId == gameId 
                      &amp;&amp; p.GameDate == gameDate
                      &amp;&amp; p.GamePlayerId == playerId
                      &amp;&amp; p.ActionTypeId == actionTypeId
                      &amp;&amp; p.PrevBoardPosition == prevBoardposition
                      &amp;&amp; (p.ActionTargetId == null || p.ActionTargetId == actionTargetId)
                  select p).FirstOrDefault();
  if (existing == null)
  {
      // create new action record...
  }
  else
  {
      // Update existing game action record...
  }
  </code></pre>
  
  <p>In this instance, the passed values are:</p>
  
  <pre><code>int gameId = 34
  DateTime gameDate = {03/05/2013 00:00:00}
  int actionTypeId = 1
  int? prevBoardposition = null
  int? actionTargetId = 52
  </code></pre>
  
  <p>And a record exists with these values (but null is returned by the query):</p>
  
  <pre><code>GameActionId    ActionTypeId    GameId  GameDate    GamePlayerId    ActionTargetId  PrevBoardPosition   MoveCount
  2125            1               34      2013-05-03  220             NULL            NULL                13
  </code></pre>
  
  <p>The equivalent SQL generated should be something like this (and this does correctly return the above record):</p>
  
  <pre><code>SELECT [GameActionId]
        ,[ActionTypeId]
        ,[GameId]
        ,[GameDate]
        ,[GamePlayerId]
        ,[ActionTargetId]
        ,[PrevBoardPosition]
        ,[MoveCount]
    FROM [dbo].[GameAction]
    where [GameId]=34 and [GamePlayerId] = 220 
          and [GameDate] = '20130503' 
          and [ActionTypeId]=1 
          and ([PrevBoardPosition] is null or [ActionTargetId]=52)
  </code></pre>
  
  <p>Is this a problem with null matching nullable ints or is it something else I have overlooked?</p>
  
  <h2>Update:</h2>
  
  <p>The generated SQL query sent to the server is:</p>
  
  <pre><code>SELECT 
  [Extent1].[GameActionId] AS [GameActionId], 
  [Extent1].[ActionTypeId] AS [ActionTypeId], 
  [Extent1].[GameId] AS [GameId], 
  [Extent1].[GameDate] AS [GameDate], 
  [Extent1].[GamePlayerId] AS [GamePlayerId], 
  [Extent1].[ActionTargetId] AS [ActionTargetId], 
  [Extent1].[PrevBoardPosition] AS [PrevBoardPosition], 
  [Extent1].[MoveCount] AS [MoveCount]
  FROM [dbo].[GameAction] AS [Extent1]
  WHERE ([Extent1].[GameId] = @p__linq__0) AND ([Extent1].[GameDate] = @p__linq__1) AND ([Extent1].[GamePlayerId] = @p__linq__2) AND ([Extent1].[ActionTypeId] = @p__linq__3) AND ([Extent1].[PrevBoardPosition] = @p__linq__4) AND ([Extent1].[ActionTargetId] = @p__linq__5 OR [Extent1].[ActionTargetId] IS NULL)
  </code></pre>