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.
Concurrency-handling with Oracle in EF Code First
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) {
// ...
}
}
}
}
}