Optimistic concurrency in Entity Framework Core

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
ChrisGO
Posts: 3
Joined: Tue 06 Aug 2019 15:35

Optimistic concurrency in Entity Framework Core

Post by ChrisGO » Mon 16 Sep 2019 21:03

I'm trying to use dotConnect 7.14.1470.0 with EFCore 2.2.6 in a .NET-Framework 4.8 application.

For optimistic concurrency I tried your example at viewtopic.php?f=3&t=38310&p=136147&hilit=xmin#p136147.

The examples throws a NotSupportedException at ctx1.SaveChanges() here:

Code: Select all

using (var ctx1 = new MyContext())
using (var ctx2 = new MyContext())
{
	var item1 = ctx1.MyClasses.Where(t => t.FStringField == "text").FirstOrDefault();
	var item2 = ctx2.MyClasses.Where(t => t.FStringField == "text").FirstOrDefault();
	item1.FStringField = "text_mod";
	item2.FStringField = "text_mod";
	
	
	ctx1.SaveChanges(); // <-- NotSupportedException is thrown.
	
	
	ctx2.SaveChanges();
}
After some testing it seems that your EFCore-Provider can't generate UPDATE statements with properties that have a [DatabaseGenerated(DatabaseGeneratedOption.Computed)] attribute.

When I change DatabaseGeneratedOption.Computed to DatabaseGeneratedOption.Identity it runs, but the call to SaveChanges() doesn't change item1.xmin to the new value from the database.

Is there any way to use optimistic concurrency with dotConnect for PostgreSQL and EFCore?

The complete NotSupportedException is:

System.NotSupportedException
HResult=0x80131515
Message=Specified method is not supported.
Source=Devart.Data.PostgreSql.Entity.EFCore
StackTrace:
at Devart.Data.PostgreSql.Entity.m.a(StringBuilder A_0, Int32 A_1)
at Microsoft.EntityFrameworkCore.Update.UpdateSqlGenerator.AppendWhereAffectedClause(StringBuilder commandStringBuilder, IReadOnlyList`1 operations)
at Microsoft.EntityFrameworkCore.Update.UpdateSqlGenerator.AppendSelectAffectedCommand(StringBuilder commandStringBuilder, String name, String schema, IReadOnlyList`1 readOperations, IReadOnlyList`1 conditionOperations, Int32 commandPosition)
at Microsoft.EntityFrameworkCore.Update.UpdateSqlGenerator.AppendUpdateOperation(StringBuilder commandStringBuilder, ModificationCommand command, Int32 commandPosition)
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.UpdateCachedCommandText(Int32 commandPosition)
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.GetCommandText()
at Devart.Common.Entity.cu.CreateStoreCommand()
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(DbContext _, ValueTuple`2 parameters)
at Microsoft.EntityFrameworkCore.Storage.Internal.NoopExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IReadOnlyList`1 entries)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
at EFCoreTest.Program.Main(String[] args)

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Optimistic concurrency in Entity Framework Core

Post by Shalex » Wed 25 Sep 2019 20:52

Please send us your test project with the DDL/DML script. We will investigate it and look for a solution.

ChrisGO
Posts: 3
Joined: Tue 06 Aug 2019 15:35

Re: Optimistic concurrency in Entity Framework Core

Post by ChrisGO » Thu 26 Sep 2019 16:49

I just sent you the test project via your contact form.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Optimistic concurrency in Entity Framework Core

Post by Shalex » Wed 02 Oct 2019 20:15

Thank you for the test project. We have received it and are processing your request.

Post Reply