Page 1 of 1

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

Posted: Wed 06 Jun 2018 12:18
by Raghu
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.

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

Posted: Thu 07 Jun 2018 18:39
by Shalex
We have sent a test project to you. Please modify it for reproducing and upload to some file exchange server.

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

Posted: Thu 07 Jun 2018 19:22
by Raghu
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.

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

Posted: Fri 08 Jun 2018 19:05
by Raghu
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.

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

Posted: Tue 12 Jun 2018 14:18
by Shalex
We cannot reproduce the problem. We have asked for the additional information by email.

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

Posted: Wed 13 Jun 2018 16:23
by Raghu
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.

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

Posted: Fri 15 Jun 2018 16:46
by Shalex
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.

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

Posted: Fri 15 Jun 2018 17:46
by Shalex
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).

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

Posted: Fri 15 Jun 2018 17:48
by Shalex
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

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

Posted: Sat 16 Jun 2018 13:50
by Raghu
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.

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

Posted: Tue 19 Jun 2018 18:19
by Shalex
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.

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

Posted: Mon 25 Jun 2018 09:27
by Shalex
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));
  }

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

Posted: Tue 17 May 2022 08:49
by KumG
Hi,


I have the same problem even with the last version of DotConnect for Oracle and EF 6.4.4 and using

Code: Select all

modelBuilder.Properties<DateTime>().Configure(p => p.HasPrecision(6));
didn't help.

Is there another solution ?

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

Posted: Mon 18 Jul 2022 12:12
by chukahu293
I have not received any mail regarding this. please let me know in post if any additional information required.

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

Posted: Wed 05 Oct 2022 10:16
by Shalex

Code: Select all

      // DDL
      // create table sample(ID number(12) primary key, NAME varchar2(32), AMOUNT number(12), DOJ TIMESTAMP);

      using (var context = new MyDbContext()) {
        var data = new SAMPLE() { ID = 1, DOJ = DateTime.Now };
        context.SAMPLEs.Add(data);
        context.SaveChanges();
      }
      
      // Devart.Data.Oracle v10.0
      // value stored without HasPrecision(6) -> 2022-10-05 12:27:52.000000
      // value stored with HasPrecision(6)    -> 2022-10-05 12:31:21.060312
Please download sample from https://download.devart.com/sample/t=37271_forum.zip. If this doesn't help, upload a test project to some file exchange server and contact us via our contact form.