Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimistic concurrency doesn't works: no OptimisticConcurrencyException is thrown [DNET400] #403

Closed
firebird-automations opened this issue Nov 16, 2011 · 2 comments

Comments

@firebird-automations
Copy link

Submitted by: Dennis (dennis.petrov)

Duplicates DNET738

How to reproduce the bug:

1) Create POCO entity class:

public class TestEntity
{
public int Id { get; private set; }
public string Name { get; set; }
public long? ObjectVersion { get; private set; }
}

2) Configure this class with code first.

2.1) "Id" must be an identity property:

		Property\(obj =\> <http://obj.Id>\)
			\.HasDatabaseGeneratedOption\(DatabaseGeneratedOption\.Identity\);

2.2) "ObjectVersion" must be a computed concurrency token:

		Property\(obj =\> obj\.ObjectVersion\)
			\.HasDatabaseGeneratedOption\(DatabaseGeneratedOption\.Computed\)
			\.HasColumnName\("ObjectVersion"\)
			\.IsConcurrencyToken\(true\);

3) Create Firebird database:
3.1) one table, corresponding to the entity type;
3.2) the sequence to generate values for "Id" column and the trigger (before insert) to set values of "Id" column;
3.3) the sequence to generate values for "ObjectVersion" column and the trigger (before insert/update) to set values of "ObjectVersion" column;

4) Run test:
4.1) create first instance of the context, load any TestEntity entity from the database;
4.2) create second instance of the context, load [b]the same[/b] TestEntity entity from the database;
4.3) change "Name" property of entity, loaded via first instance of the context and save changes. "ObjectVersion" property will be incremented.
4.4) change "Name" property of entity, loaded via second instance of the context and save changes. "ObjectVersion" property will be set to null. No OptimisticConcurrencyException will be thrown, although it must be.

Remark: changing the type of "ObjectVersion" property to non-nullable Int64 brings to an exception, but this is materialization-related exception (trying to assign null to a non-nullable property). To throw OptimisticConcurrencyException, this query:

EXECUTE BLOCK (
p0 BLOB SUB_TYPE TEXT = @p0, p1 INT = @p1, p2 BIGINT = @p2)
RETURNS (
"ObjectVersion" BIGINT)
AS BEGIN
UPDATE "TestEntity"
SET "Name" = :p0
WHERE (("Id" = :p1) and ("ObjectVersion" = :p2))
RETURNING "ObjectVersion" INTO :"ObjectVersion";
SUSPEND;
END

must set correctly rows affected.

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Link: This issue duplicates DNET738 [ DNET738 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => Closed [ 6 ]

resolution: Duplicate [ 3 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants