As I read, the optimistic concurrency exception is thrown by ObjectContext.saveChange(), if a field typed Timestamp exist in the database, marked as fixed in the entityframework designer and a conflict happens. That doesn't work for me :/ I'm comparing the timestamps in hard code to rise the exception:
public void SaveChanges(TEntity entity, Byte[] oldTimestamp, Byte[] newTimestamp)
{
int i=0;
try
{
foreach (byte b in oldTimestamp)
{
if( !b.Equals(newTimestamp[i++])) throw new OptimisticConcurrencyException();
}
SaveChanges();
}
catch (OptimisticConcurrencyException oce)
{
Refresh(entity);
throw oce;
}
}
I don't think what i'm doing is a clean code, although the exception is raised now.