Concurrency-handling with Oracle in EF Code First

Concurrency-handling with Oracle in EF Code First

Postby quanb » Fri 21 Oct 2011 08:49

I have an entity class, which has a property Version of type int as concurrency token.
If I try to update this object, DbUpdateConcurrencyException will always be thrown,
whether I increase the Version or not , whereas it works for Mssql.


Anyone can help? Thanks.
quanb
 
Posts: 1
Joined: Fri 21 Oct 2011 08:25

Postby Shalex » Tue 25 Oct 2011 14:59

We will investigate the issue and notify you about the results as soon as possible.
Shalex
Devart Team
 
Posts: 7338
Joined: Thu 14 Aug 2008 12:44

Postby Shalex » Wed 02 Nov 2011 14:59

dotConnect for Oracle v 6.50.237 works correctly with the following code. Please modify this sample (or send us yours) to reproduce the problem in our environment. Also specify the expected behaviour and the one you have obtained.
Code: Select all
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using Devart.Data.Oracle;
using Devart.Data.Oracle.Entity.Configuration;

namespace Test {

  public class SomeTable {
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }
    public string Text { get; set; }

    [ConcurrencyCheck]
    public int Version { get; set; }
  }

  public class MyDbContext : DbContext {

    public MyDbContext(DbConnection conneciton)
      : base(conneciton, false) {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder) {

      modelBuilder.Conventions.Remove();
      modelBuilder.Conventions.Remove();
    }

    public DbSet SomeTable { get; set; }
  }

  public class Program {

    public static void Execute() {

      var monitor = new OracleMonitor() { IsActive = true };

      var config = OracleEntityProviderConfig.Instance;
      config.Workarounds.IgnoreSchemaName = true;
      config.DatabaseScript.Schema.DeleteDatabaseBehaviour = DeleteDatabaseBehaviour.ModelObjectsOnly;

      System.Data.Entity.Database.SetInitializer(new DropCreateDatabaseAlways());

      using (MyDbContext context = new MyDbContext(new OracleConnection("User Id=scott;Password=tiger;Server=orcl1120;"))) {
        SomeTable newRecord = new SomeTable() { Text = "123", Version = 1 };
        context.SomeTable.Add(newRecord);
        context.SaveChanges();

        var item1 = context.SomeTable.Single(t => t.Text == "123");
        item1.Text = "new value 1";
        item1.Version++;

        using (MyDbContext secondContext = new MyDbContext(new OracleConnection("User Id=scott;Password=tiger;Server=orcl1120;"))) {
          System.Data.Entity.Database.SetInitializer(null);
          var item2 = secondContext.SomeTable.Single(t => t.Text == "123");
          item2.Text = "new value 2";
          item2.Version++;
          secondContext.SaveChanges(); // commited successfully
        }

        try {
          context.SaveChanges(); // exception
        }
        catch (OptimisticConcurrencyException ex) {
          // ...
        }

      }
    }

  }

}
Shalex
Devart Team
 
Posts: 7338
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for Oracle