Skip to content

Commit

Permalink
- 修复 Repository + AuditValue + Attach 问题;#1931 #1746
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Nov 24, 2024
1 parent 55000de commit cc17960
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 239 deletions.
26 changes: 14 additions & 12 deletions Examples/base_entity/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ static void Main(string[] args)
//.UseSlaveWeight(10, 1, 1, 5)


.UseConnectionString(FreeSql.DataType.Firebird, @"database=localhost:D:\fbdata\EXAMPLES.fdb;user=sysdba;password=123456;max pool size=5")
//.UseConnectionString(FreeSql.DataType.Firebird, @"database=localhost:D:\fbdata\EXAMPLES.fdb;user=sysdba;password=123456;max pool size=5")
//.UseQuoteSqlName(false)

//.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;min pool size=1;Max pool size=3;AllowLoadLocalInfile=true")
Expand Down Expand Up @@ -619,6 +619,18 @@ static void Main(string[] args)
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
#endregion

fsql.Aop.AuditValue += (_, e) =>
{

};

var tt1 = new ProjectItem { ID = 1, MaxQuantity = 0, Code = null, Name = null };
var tt2 = new ProjectItem { ID = 1, MaxQuantity = 100, Code = null, Name = null };
var repot2 = fsql.GetRepository<ProjectItem>();

repot2.Attach(tt1);
var nt1 = repot2.Update(tt2);

fsql.Delete<User1>().Where("1=1").ExecuteAffrows();
fsql.Insert(new List<User1>
{
Expand Down Expand Up @@ -721,17 +733,7 @@ static void Main(string[] args)

fsql.Select<User1>().Where(a => a.Id == new Guid("xxx")).ToList(a => new Guid("zzz"));

fsql.Aop.AuditValue += (_, e) =>
{

};

var tt1 = new ProjectItem { ID = 1, MaxQuantity = 0, Code = null, Name = null };
var tt2 = new ProjectItem { ID = 1, MaxQuantity = 100, Code = null, Name = null };
var repot2 = fsql.GetRepository<ProjectItem>();

repot2.Attach(tt1);
var nt1 = repot2.Update(tt2);


var fsql2 = fsql;
// 动态构建实体类型,树形结构,引用自身类型
Expand Down
7 changes: 6 additions & 1 deletion FreeSql.DbContext/DbSet/DbSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ void AttachPriv(IEnumerable<TEntity> data, bool isAuditValue)
{
if (isAuditValue)
{
FreeSql.Internal.CommonProvider.UpdateProvider<TEntity>.AuditDataValue(this, item, _db.OrmOriginal, _table, null); //与 CanUpdate 同步
foreach (var col in _table.Columns.Values) //#1746
{
object val = col.GetValue(item);
if (val == null && col.Attribute.MapType == typeof(string) && col.Attribute.IsNullable == false)
col.SetValue(item, val = "");
}
_db.Options.AuditValue?.Invoke(new DbContextAuditValueEventArgs(Aop.AuditValueType.Update, _table.Type, item));
}
var key = _db.OrmOriginal.GetEntityKeyString(_entityType, item, false);
Expand Down
2 changes: 1 addition & 1 deletion FreeSql.DbContext/FreeSql.DbContext.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.5.100-preview20241123</Version>
<Version>3.5.100-preview20241124</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
6 changes: 3 additions & 3 deletions FreeSql/Extensions/EntityUtilExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ public static object GetPropertyValue(this TableInfo table, object entity, strin
)
});
exps.AddRange(new Expression[] {
Expression.Return(returnTarget, var2Ret),
Expression.Label(returnTarget, Expression.Default(typeof(object)))
});
Expression.Return(returnTarget, var2Ret),
Expression.Label(returnTarget, Expression.Default(typeof(object)))
});
return Expression.Lambda<Func<object, object>>(Expression.Block(new[] { var1Parm, var2Ret }, exps), new[] { parm1 }).Compile();
});
return func(entity);
Expand Down
Loading

0 comments on commit cc17960

Please sign in to comment.