I need to perform a delta select on a table (return only records that have changed, since a certain TimeStamp), and I must use a TimeStamp column. In SQL, this is easy:
@DeltaStamp TIMESTAMP
...
select *
from table
where timestamp > @DeltaStamp
In Linq2SQL I can get the max timestamp easily:
var maxStamp = MyTable
.OrderByDescending(x => x.TimeStamp)
.Take(1)
.FirstOrDefault().TimeStamp;
But How can I perform the delta query?
var newRecords = MyTable
.Where(x => x.TimeStamp > maxStamp);
This doesn’t compile with:
Operator '>' cannot be applied to operands of type
'System.Data.Linq.Binary' and 'System.Data.Linq.Binary'
Cheers.
This is not possible in L2S. A SQL Timestamp column is not a dateTime column. It is a binary, and L2S treats it as such. Therefore, you are unable to do what you want to do, at least not “out of the box”. You could create your own Comparer as follows:
This should work, or be close.