How should I compare rowversion
fields using Entity Framework? I have one table which has a rowversion
column, I want to get data from tables for which
Here is what we did to solve this. Use a compare extension like this:
public static class EntityFrameworkHelper
{
public static int Compare(this byte[] b1, byte[] b2)
{
throw new Exception("This method can only be used in EF LINQ Context");
}
}
Then you can do this:
byte[] rowversion = .....somevalue;
_context.Set().Where(item => item.RowVersion.Compare(rowversion) > 0);
The reason this works without a C# implementation is because the Compare
extension method is never actually called, and EF LINQ simplifies x.Compare(y) > 0
down to x > y
.