Ran into an interesting bug today. I’m working with a client that’s using .net 4.5.1, EF 6.1.3, and is in the process of upgrading to SQL Server 2016.
When we did the update, we suddenly had entities that were being detected as being different, even though the data was exactly the same. This was causing us to get unexpected concurrency exceptions.
The following sql would be generated by entity framework:
exec sp_executesql N'UPDATE [dbo].[MyTable]
SET [StateLastChangedDate] = @0
WHERE (([Id] = @1) AND ([LastEdited] = @2))
SELECT [LastEdited]
FROM [dbo].[MyTable]
WHERE @@ROWCOUNT > 0 AND [Id] = @1',N'@0 datetime2(7),@1 uniqueidentifier,@2 binary(8)',@0='2016-08-04 17:28:17.2366667',@1='FC66D162-1801-409C-8574-4B1900C72B2E',@2=0x0000000000004D3B
StateLastChangedDate would be identical to what it was previously. Same ticks and everything.
We found two solutions:
1. Change the compatibility mode to Sql Server 2014
2. Upgrade to .net 4.6.2
Both seemed to eliminate the issue with a field being detected as being changed when it shouldn’t have been.
