[英]EF 4.1.3 Implenting Rowversion for Concurrency is not working
I have got a BaseEntity class which contains a, byte array called stamp, id and state, which every Entity inherits from I am mapping the stamp to 我有一个BaseEntity类,该类包含一个称为Stamp,ID和State的字节数组,每个Entity都将从该数组继承我将Stamp映射到
Property(t => t.Stamp).IsRequired().IsRowVersion();
this is set in BaseEntityConfiguration which is set like this 这是在这样设置的BaseEntityConfiguration中设置的
public BaseEntityConfiguration<T> : EntityTypeConfiguration<T> where T :B aseEntity
The mapping is done like this 映射是这样完成的
var baseMapConfiguration = new BaseEntityConfiguration<EntityA>();
modelBuilder.Configurations.Add(baseMapConfiguration);
var entityAMap = new EntityAMap(baseMapConfiguration);
The database has Stamp ROWVERSION NOT NULL; 数据库具有Stamp ROWVERSION NOT NULL; on the Table EntityA I have code that handles DbUpdateConcurrencyException but this does not get caught even though the stamps are different Also there is no where clause on with the Stamp field which I would expected
在表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]
As you seen no where statement I have also tried it from the with a normal mapping set up but still get the same result 如您所见,没有where语句,我也使用正常映射设置从尝试过,但仍然得到相同的结果
**I have found the problem EF is getting the latest Rowversion instead of the passed in one, How can I stop this. **我发现问题是EF正在获取最新的Rowversion而不是传入的,我该如何停止。 **
**
if (!EntityA.Stamp.Equals(orignal.Stamp))
{
ctx.Entry(orignal).OriginalValues["Stamp"] = xmlFile.Stamp;
}
I was missing these line of codes from the DAL, this is stop EF putting the current stamp as the search criteria. 我从DAL中缺少了这些代码行,这是停止EF将当前戳记用作搜索条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.