为什么EFContextProvider 1.4.16在尝试更新枚举值时会抛出DbUpdateConcurrencyException?

时间:2014-07-22 12:57:43

标签: breeze

我试图保存单个更改 - 枚举属性值更新。在服务器上调用EFContextProvider.SaveChanges(),但生成的SQL是错误的,当由EFContextProvider执行时,它会抛出System.Data.Entity.Infrastructure.DbUpdateConcurrencyException。

enum属性定义如下:

        public virtual System.Nullable<StanZleceniaOplaty> Stan { get; set; }

        public enum StanZleceniaOplaty : int
        {
                    Created,
                    Started,
                    Canceled,
                    Rejected,
                    Paid
        }

实体ZlecenieOplaty的EntityTypeConfiguration使用以下代码配置Stan:

        this
            .Property(p => p.Stan)
                .IsConcurrencyToken()
                .HasColumnType("int"); 

请注意,此枚举属性 IsConcurrencyToken

我将枚举从Created更改为Cancelled并调用SaveChanges()。 我可以看到EFContextProvider生成的SQL再次出现在EF 6.1 DB上是错误的([Stan]没有改变,因为@ 0 == @ 2,@ 2有错误的值 - 应该是0)。

exec sp_executesql N'UPDATE [dbo].[ZlecenieOplaty]
SET [Stan] = @0
WHERE (([Id] = @1) AND ([Stan] = @2))
SELECT [NrZlecenia]
FROM [dbo].[ZlecenieOplaty]
WHERE @@ROWCOUNT > 0 AND [Id] = @1',
N'@0 int,@1 int,@2 int',
@0=2,
@1=3,
@2=2

实际上会抛出以下异常。

System.Data.Entity.Infrastructure.DbUpdateConcurrencyException occurred
  HResult=-2146233087
  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. Refresh ObjectStateManager entries.
  Source=EntityFramework
  StackTrace:
       at System.Data.Entity.Internal.InternalContext.SaveChanges()
       at Alcance.Entities.AlcanceDbContext.SaveChanges() in d:\Develop\alcance\src\dev\Alcance.Data\Model\AlcanceModel.AlcanceDbContext.Connection.cs:line 121
  InnerException: System.Data.Entity.Core.OptimisticConcurrencyException
       HResult=-2146233087
       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. Refresh ObjectStateManager entries.
       Source=EntityFramework
       StackTrace:
            at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.ValidateRowsAffected(Int64 rowsAffected, UpdateCommand source)
            at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
            at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
            at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
            at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute[TResult](Func`1 operation)
            at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
            at System.Data.Entity.Internal.InternalContext.SaveChanges()
       InnerException:

我打开了https://github.com/Breeze/breeze.server.net/issues/8

有人可以确认这是一个错误吗?

0 个答案:

没有答案