DbUpdateConcurrencyException when using Devart dotConnect (9.5.454.0) with Oracle in EF Code First

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
Raghu
Posts: 5
Joined: Wed 06 Jun 2018 09:30

DbUpdateConcurrencyException when using Devart dotConnect (9.5.454.0) with Oracle in EF Code First

Post by Raghu » Wed 06 Jun 2018 12:18

I have an entity class in which few columns have IsConcurrencyToken() configuration defined on them.
For most of entites IsConcurrencyToken() is defined on column type DATE.
Ex: this.Property(t => t.column_name).HasColumnName("column_name").HasColumnType("DATE").IsConcurrencyToken();

Any save operation on this object is resulting in DbUpdateConcurrencyException.
I was able to save the object if i remove IsConcurrencyToken() on defined columns though.

I am facing this issue after migrating from Devart dotConnect 8.5.616 to 9.5.454.0; same scenario is working fine with Devart dotConnect (V 8.5.616.0)

Below are the exception details:
An exception of type 'System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' occurred and was caught.

Type : System.Data.Entity.Infrastructure.DbUpdateConcurrencyException, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded.

Any help on this is highly appreciated.

Thanks.

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

Re: DbUpdateConcurrencyException when using Devart dotConnect (9.5.454.0) with Oracle in EF Code First

Post by Shalex » Thu 07 Jun 2018 18:39

We have sent a test project to you. Please modify it for reproducing and upload to some file exchange server.

Raghu
Posts: 5
Joined: Wed 06 Jun 2018 09:30

Re: DbUpdateConcurrencyException when using Devart dotConnect (9.5.454.0) with Oracle in EF Code First

Post by Raghu » Thu 07 Jun 2018 19:22

I have not received any test project on my registered mail ID.
If possible can you resend it again and let me know how to send it back after modification.

Thanks.

Raghu
Posts: 5
Joined: Wed 06 Jun 2018 09:30

Re: DbUpdateConcurrencyException when using Devart dotConnect (9.5.454.0) with Oracle in EF Code First

Post by Raghu » Fri 08 Jun 2018 19:05

I found exact root cause for this issue :
With devart dotConnect(V 9.5.454.0) Insert/Update/Select operations on oracle DB column of type TIMESTAMP the milliseconds value retrieved/updated as Zero's(Ex:10-Sep-02 14:10:10.000000) instead of actual value.

It is not possible to share sample application but i can post the steps to reproduce the issue:

1. Create table with at-least one column of type TIMESTAMP and insert sample data into it. PFB script :
create table sample(ID number(12),NAME varchar2(32),AMOUNT number(12),DOJ TIMESTAMP)
insert into sample values(1,'test data',100,systimestamp)


2. Define an entity and configure DOJ column with IsConcurrencyToken()
Ex: protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Sample>()
.Property(b => b.DOJ)
.HasColumnName("DOJ").IsConcurrencyToken();
}


3. Update amount column of sample table
Ex: var data =DbContext.Set<Sample>().Where(t => t.Id == 1).FirstOrDefault();
data.Amount = 200;
DbContext.Entry(data).State = EntityState.Modified;
DbContextContext.SaveChanges();


Upon performing update operation on column using devart dotConnect(V 9.5.454.0) it throws below exception:

Exception : Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded.

Same scenario is working fine with Devart dotConnect (V 8.5.616.0)

Please let me know the resolution at earliest.

Thanks.

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

Re: DbUpdateConcurrencyException when using Devart dotConnect (9.5.454.0) with Oracle in EF Code First

Post by Shalex » Tue 12 Jun 2018 14:18

We cannot reproduce the problem. We have asked for the additional information by email.

Raghu
Posts: 5
Joined: Wed 06 Jun 2018 09:30

Re: DbUpdateConcurrencyException when using Devart dotConnect (9.5.454.0) with Oracle in EF Code First

Post by Raghu » Wed 13 Jun 2018 16:23

I have not received any mail regarding this. please let me know in post if any additional information required.

Below are the steps to replicate issue easily :

1. create a table in oracle DB using this script
create table sample(ID number(12),DOJ TIMESTAMP)

2.Insert a record in to table with EF code first with both dotConnect versions
with version 9.5.454.0 DOJ column value will be inserted as: Ex:10-Sep-02 14:10:10.000000
with version 8.5.616.0 DOJ column value will be inserted as: Ex:10-Sep-02 14:10:10.458956
Milliseconds value will be inserted as zero with 9.5.454.0 and even with latest version 9.5.520

3. Even when we try to retrieve value of DOJ column Milliseconds value retrieved as zero's with 9.5.454.0

Thanks.

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

Re: DbUpdateConcurrencyException when using Devart dotConnect (9.5.454.0) with Oracle in EF Code First

Post by Shalex » Fri 15 Jun 2018 16:46

Raghu wrote:
Fri 08 Jun 2018 19:05
create table sample(ID number(12),NAME varchar2(32),AMOUNT number(12),DOJ TIMESTAMP)
Raghu wrote:
Fri 08 Jun 2018 19:05
modelBuilder.Entity<Sample>()
.Property(b => b.DOJ)
.HasColumnName("DOJ").IsConcurrencyToken();
}
You should map the DOJ column type explicitly: .HasColumnType("timestamp");
After this, the DOJ column in database will have milliseconds information.

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

Re: DbUpdateConcurrencyException when using Devart dotConnect (9.5.454.0) with Oracle in EF Code First

Post by Shalex » Fri 15 Jun 2018 17:46

Actually, the DateTime properties should be mapped to timestamp by default if you do not specify config.CodeFirstOptions.UseDateTimeAsDate=true; in your code explicitly (default value is False).

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

Re: DbUpdateConcurrencyException when using Devart dotConnect (9.5.454.0) with Oracle in EF Code First

Post by Shalex » Fri 15 Jun 2018 17:48

If this doesn't help:

a) download https://www.devart.com/pub/259376_ticket.zip. Open the project in Visual Studio, right click *.edml > Open With > Entity Developer. Then navigate to Tools > Entity Developer > Database Explorer and Edit Connection Properties to adjust them to your environment. Save the *.edml. Run the code. Does the error occur? If necessary, modify it and upload to some file exchange server and give us the download link

b) specify your connection string (roughly, without credentials)

c) tell us the version (x.xx) of your Oracle Server

Raghu
Posts: 5
Joined: Wed 06 Jun 2018 09:30

Re: DbUpdateConcurrencyException when using Devart dotConnect (9.5.454.0) with Oracle in EF Code First

Post by Raghu » Sat 16 Jun 2018 13:50

Shalex wrote:
Fri 15 Jun 2018 16:46
You should map the DOJ column type explicitly: .HasColumnType("timestamp");
After this, the DOJ column in database will have milliseconds information.
I have mapped DOJ column as TIMESTAMP explicitly even then milliseconds value is saved/retrieved as zero's.

modelBuilder.Entity<Sample>()
.Property(b => b.DOJ)
.HasColumnName("DOJ").HasColumnType("timestamp").IsConcurrencyToken();
}

I will modify sample application that was shared with me to replicate the issue and share the same with you asap.

thanks.

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

Re: DbUpdateConcurrencyException when using Devart dotConnect (9.5.454.0) with Oracle in EF Code First

Post by Shalex » Tue 19 Jun 2018 18:19

We have reproduced the difference in behavior between v8.5 and v9.5, it is caused by missing .Precision(6) in mapping.

We will notify you about the result of our investigation.

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

Re: DbUpdateConcurrencyException when using Devart dotConnect (9.5.454.0) with Oracle in EF Code First

Post by Shalex » Mon 25 Jun 2018 09:27

There is no timeframe for the fix of mapping with missing .Precision(6).

Please use a workaround with setting .Precision(6) for the timestamp columns. You can implement this workaround for all DateTime properties of a current context in the end of the OnModelCreating method via simple convention:

Code: Select all

  protected override void OnModelCreating(DbModelBuilder modelBuilder)
  {
      // ...
      modelBuilder.Properties<DateTime>()
      .Configure(p => p.HasPrecision(6));
  }

Post Reply