0

我有一个 BaseEntity 类,它包含一个名为 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;在表 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 而不是传入的,我该如何阻止它。**

4

1 回答 1

0
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.

于 2016-02-15T10:35:20.587 回答