I have a simple web page used for data entry (built with .NET 4.5 and EF5). Each time a user updates an entry, a new row is created with a TimeStamp value bigger than the previous row that was inserted (SQL Server guarantees that).
In the DB, the raw data looks like the following. In brief, the data mean that the TransactionNumber = 1 was added once and then updated two times.
+---------------+-------------------+-----------+--------------------+
| TransactionId | TransactionNumber | Comment | TimeStamp |
+---------------+-------------------+-----------+--------------------+
| 1 | 1 | Bla | 0x00000000000007D1 |
| 2 | 1 | BlaBla | 0x00000000000007D2 |
| 3 | 1 | BlaBlaBla | 0x00000000000007D3 |
| 4 | 2 | Hello | 0x00000000000007D4 |
+---------------+-------------------+-----------+--------------------+
I'd like to write a Linq query that get only the latest value for each TransactionNumber. Considering the data above, my query would return the following result.
+---------------+-------------------+-----------+--------------------+
| TransactionId | TransactionNumber | Comment | TimeStamp |
+---------------+-------------------+-----------+--------------------+
| 3 | 1 | BlaBlaBla | 0x00000000000007D3 |
| 4 | 2 | Hello | 0x00000000000007D4 |
+---------------+-------------------+-----------+--------------------+
The biggest issue I am facing so far is that the TimeStamp column is of type byte[] and I am not sure how to make the comparison of bytes possible. Any idea how to do this?
public class Transaction
{
// ...
[Timestamp]
public Byte[] TimeStamp { get; set; }
}