繁体   English   中英

EF 4.1.3阻止行版本并发不起作用

[英]EF 4.1.3 Implenting Rowversion for Concurrency is not working

我有一个BaseEntity类,该类包含一个称为Stamp,ID和State的字节数组,每个Entity都将从该数组继承我将Stamp映射到

 Property(t => t.Stamp).IsRequired().IsRowVersion();

这是在这样设置的BaseEntityConfiguration中设置的

 public BaseEntityConfiguration<T> : EntityTypeConfiguration<T> where T :B aseEntity

映射是这样完成的

var baseMapConfiguration = new BaseEntityConfiguration<EntityA>();
           modelBuilder.Configurations.Add(baseMapConfiguration);
           var entityAMap = new EntityAMap(baseMapConfiguration);

数据库具有Stamp ROWVERSION NOT NULL; 在表EntityA上,我有处理DbUpdateConcurrencyException的代码,但是即使图章不同,也没有捕获到该代码。对于Stamp字段,我没有期望的where子句

    SELECT 
[Extent1].[Id] AS [Id], 
[Extent1].[LastModified] AS [LastModified], 
[Extent1].[CreatedDate] AS [CreatedDate], 
[Extent1].[Stamp] AS [Stamp]
FROM [dbo].[EntityA] AS [Extent1]

如您所见,没有where语句,我也使用正常映射设置从尝试过,但仍然得到相同的结果

**我发现问题是EF正在获取最新的Rowversion而不是传入的,我该如何停止。 **

if (!EntityA.Stamp.Equals(orignal.Stamp))
{
     ctx.Entry(orignal).OriginalValues["Stamp"] = xmlFile.Stamp;
}

我从DAL中缺少了这些代码行,这是停止EF将当前戳记用作搜索条件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM