2

One of my models, let's call it "Comment" has a timestamp column/member

I had defined it originally as:

[Required]
public DateTime Timestamp { get; set; }

I had some methods in other parts of my code that would get the latest comments after a specific time, so it would grab all comments with a timestamp greater than some value.

I recently came across an article by Julie Lerman about the timestamp data annotation for entity framework (http://msdn.microsoft.com/en-US/data/jj591583#c_8b121aeb433a4ab19d538bc8c20a58fb) and she suggested using a byte array with the [Timestamp] data annotation for correct storage in the database.

[Timestamp]
public Byte[] Timestamp { get; set; }

I am not sure how to handle finding updated records with the byte array. From what I understand, the system handles timestamp byte arrays by just incrementing them by 1 every time they are updated, but that is a relative value.

What am I missing?

mvanella
  • 3,456
  • 3
  • 19
  • 23
  • From what I gather `byte[]` is used more for `concurrency checking`. – sakura-bloom Aug 16 '13 at 18:15
  • 1
    `Timestamp`is a misleading name. It actually is no timestamp, it is a `rowversion`. The value is incremented by one over the whole server and is guaranteed to be unique. The SQL type is also called `rowversion`. – user2674389 Aug 16 '13 at 19:15
  • I agree with user2674389 if your using modelBuilder.Entity().Property(t => t.TimeStamp).IsConcurrencyToken() ... it appears the 'timestamp' does increment by 1 so is really a row version. – andrew pate Oct 02 '17 at 12:27

1 Answers1

2

Sounds like you're not using the Timestamp property as a concurrency check but as a standard property. I'd revert back to a DateTime

Ryan Amies
  • 4,902
  • 1
  • 21
  • 36