简体   繁体   English

为什么某些属性值已更改实体 state 在 EF Core 2.2.6 中为“UnChanged”

[英]Why some properties value was changed entity state is `UnChanged` in EF Core 2.2.6

I use EF Core 2.2.6.我使用 EF Core 2.2.6。 I come across one strange.我遇到一个奇怪的。 I fetched one entity from DB then I changed one property value.我从数据库中获取了一个实体,然后我更改了一个属性值。 I looked ChangeTraker I see entity state is UnChanged .我查看了 ChangeTracker 我看到实体 state 是UnChanged But entity property value was changed.但实体属性值已更改。 The Most part of stange is that EF create update query . stange 的大部分内容是 EF 创建update query Everythink works fine. Everythink工作正常。 I would like to learn why it is working like this.我想了解它为什么会这样工作。 my example is following我的例子如下

 var person = _unitOfWork.PersonRepository.Get(x => x.Id == 20);
 person.RegUserId=5;
 _unitOfWork.Commit();

public TEntity Get(Expression<Func<TEntity, bool>> predicate)
{
  return _dbset.FirstOrDefault(predicate);
}

在此处输入图像描述 在此处输入图像描述

EntityState is recalculated only when ChangeTracker.DetectChanges() is called, typically during SaveChanges(). EntityState 仅在调用 ChangeTracker.DetectChanges() 时重新计算,通常在 SaveChanges() 期间。

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

相关问题 EF Core &gt; 删除实体(软删除)&gt; 实体 State 保持不变 - EF Core > Delete entity (Soft Delete) > Entity State remains Unchanged 为什么 EF Core 2.2.6 不进行垃圾回收? - Why EF Core 2.2.6 does not garbage collect? 如何判断 EF Core 实体上的哪些属性已更改? - How to tell which properties have changed on an EF Core Entity? EF Core - 具有动态属性的实体 - EF Core - Entity with Dynamic Properties EF Core 2.2.6 - Map 实体或查询 SQL 语句(我不想创建视图) - EF Core 2.2.6 - Map Entity or Query to a SQL Statement (I don't want to create a view) 为什么Entity Id的AutoIncrement异常变化,如何重置? - ASP.NET 核心,EF 核心 - Why has AutoIncrement of Entity Id changed abnormally, and how to reset it? - ASP.NET Core, EF Core EF Core 3.0:实体中的多个导航属性 - EF Core 3.0 : Multiple navigation properties in an entity 如何使用 EF 核心中的相关实体属性进行排序 - How to order by with related entity properties in EF core Entity Framework Core 3.0 查询导致“SqlException: 'Execution Timeout Expired'”和 tempdb 变满。 适用于 EF Core 2.2.6 - Entity Framework Core 3.0 query causes “SqlException: 'Execution Timeout Expired'” and tempdb become full. Works with EF Core 2.2.6 尽管 State=Modified,为什么 EF Core 只生成父(游戏)属性更新? - Why EF Core generates only parent(Game) properties updating despite State=Modified?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM