1

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.

Rahma
  • 255
  • 3
  • 21

1 Answers1

0

What you are doing is actually correct. If you have both old and new timestamp in the application it is not needed to do the database roundtrip to resolve concurrency, is it? Why it doesn't in database is hard to say because you didn't provide enough details but perhaps this will explain you something.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670