efcore 重复跟踪问题解决,以及数组json列,无数据的时候会更新奇怪问题发现
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
e6458e66df
commit
61ab33b3f3
|
|
@ -119,7 +119,10 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
/// <summary>EntityState.Detached的实体 修改 部分字段</summary>
|
/// <summary>EntityState.Detached的实体 修改 部分字段</summary>
|
||||||
public static void EntityModifyPartialFiled<T>(this IRaCISDBContext _dbContext, T waitModifyEntity, Expression<Func<T, T>> updateFactory) where T : Entity
|
public static void EntityModifyPartialFiled<T>(this IRaCISDBContext _dbContext, T waitModifyEntity, Expression<Func<T, T>> updateFactory) where T : Entity
|
||||||
{
|
{
|
||||||
var entityEntry = _dbContext.Entry(waitModifyEntity);
|
//解决重复跟踪问题
|
||||||
|
var tracked = _dbContext.ChangeTracker.Entries<T>().FirstOrDefault(e => e.Entity.Id.Equals(waitModifyEntity.Id));
|
||||||
|
var entityEntry = tracked?? _dbContext.Entry(waitModifyEntity);
|
||||||
|
|
||||||
//entityEntry.State = EntityState.Detached;
|
//entityEntry.State = EntityState.Detached;
|
||||||
|
|
||||||
var list = ((MemberInitExpression)updateFactory.Body).Bindings.Select(mb => mb.Member.Name)
|
var list = ((MemberInitExpression)updateFactory.Body).Bindings.Select(mb => mb.Member.Name)
|
||||||
|
|
@ -134,7 +137,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
|
|
||||||
foreach (PropertyInfo prop in list)
|
foreach (PropertyInfo prop in list)
|
||||||
{
|
{
|
||||||
_dbContext.Entry(waitModifyEntity).Property(prop.Name).IsModified = true;
|
entityEntry.Property(prop.Name).IsModified = true;
|
||||||
|
|
||||||
object value = prop.GetValue(applyObj);
|
object value = prop.GetValue(applyObj);
|
||||||
prop.SetValue(waitModifyEntity, value);
|
prop.SetValue(waitModifyEntity, value);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue