EF 4.1.3 为并发实施 Rowversion 不起作用
EF 4.1.3 Implenting Rowversion for Concurrency is not working
我有一个 BaseEntity class,它包含一个名为 stamp、id 和 state 的字节数组,每个实体都继承自我正在将 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;在 Table 实体 A 上
我有处理 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 将当前标记作为搜索条件。
我有一个 BaseEntity class,它包含一个名为 stamp、id 和 state 的字节数组,每个实体都继承自我正在将 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;在 Table 实体 A 上 我有处理 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 将当前标记作为搜索条件。