mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
修复 DbContext bug
This commit is contained in:
@ -59,11 +59,17 @@ namespace FreeSql {
|
||||
states.RemoveAt(states.Count - 1);
|
||||
return;
|
||||
}
|
||||
if (affrows == -998 || affrows == -997) { //没有执行更新
|
||||
var laststate = states[states.Count - 1];
|
||||
states.Clear();
|
||||
if (affrows == -997) states.Add(laststate); //保留最后一个
|
||||
}
|
||||
if (affrows > 0) {
|
||||
_affrows += affrows;
|
||||
var islastNotUpdated = states.Count != affrows;
|
||||
var laststate = states[states.Count - 1];
|
||||
states.Clear();
|
||||
if (islastNotUpdated) states.Add(oldinfo.state);
|
||||
if (islastNotUpdated) states.Add(laststate); //保留最后一个
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -76,6 +76,7 @@ namespace FreeSql {
|
||||
this.Key = key;
|
||||
this.Time = DateTime.Now;
|
||||
}
|
||||
public TEntity OldValue { get; set; }
|
||||
public TEntity Value { get; set; }
|
||||
public string Key { get; set; }
|
||||
public DateTime Time { get; set; }
|
||||
|
@ -156,7 +156,7 @@ namespace FreeSql {
|
||||
if (data?.Count > 0) {
|
||||
|
||||
if (cuig.Length == _table.Columns.Count)
|
||||
return data.Count;
|
||||
return ups.Length == data.Count ? -998 : -997;
|
||||
|
||||
var updateSource = data.Select(a => a.Value).ToArray();
|
||||
var update = this.OrmUpdate(null).SetSource(updateSource).IgnoreColumns(cuig);
|
||||
@ -166,6 +166,8 @@ namespace FreeSql {
|
||||
foreach (var newval in data) {
|
||||
if (_states.TryGetValue(newval.Key, out var tryold))
|
||||
_fsql.MapEntityValue(newval.Value, tryold.Value);
|
||||
if (newval.OldValue != null)
|
||||
_fsql.MapEntityValue(newval.Value, newval.OldValue);
|
||||
}
|
||||
return affrows;
|
||||
}
|
||||
@ -176,7 +178,9 @@ namespace FreeSql {
|
||||
|
||||
void UpdatePriv(TEntity data, bool isCheck) {
|
||||
if (isCheck && CanUpdate(data, true) == false) return;
|
||||
EnqueueAction(DbContext.ExecCommandInfoType.Update, this, typeof(EntityState), CreateEntityState(data));
|
||||
var state = CreateEntityState(data);
|
||||
state.OldValue = data;
|
||||
EnqueueAction(DbContext.ExecCommandInfoType.Update, this, typeof(EntityState), state);
|
||||
}
|
||||
public void Update(TEntity data) => UpdatePriv(data, true);
|
||||
public void UpdateRange(TEntity[] data) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>0.3.27</Version>
|
||||
<Version>0.3.27.1</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>
|
||||
|
Reference in New Issue
Block a user