Skip to content

Commit 87c9ca8

Browse files
committed
- 修复 DbSet/Repository CompareState 报错的问题;#1994
1 parent 89c8403 commit 87c9ca8

File tree

5 files changed

+176
-133
lines changed

5 files changed

+176
-133
lines changed

Examples/base_entity/Program.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,19 @@ static void Main(string[] args)
621621
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
622622
#endregion
623623

624+
fsql.InsertOrUpdate<AppInfoEntity>().SetSource(new AppInfoEntity { AppID = "03DN8CW8", AppName = "app_01" }).ExecuteAffrows();
625+
var repo2211 = fsql.GetRepository<AppInfoEntity>();
626+
627+
var appInfo = repo2211.Where(info => info.AppID == "03DN8CW8").First();
628+
appInfo = repo2211.Where(info => info.AppID == "03DN8CW8").First();
629+
var compareDic = new Dictionary<string, object[]>();
630+
var updateInfo = "";
631+
632+
repo2211.Attach(appInfo);
633+
appInfo.AppName = "测试";
634+
compareDic = repo2211.CompareState(appInfo);
635+
Console.WriteLine(appInfo.AppName);
636+
624637
var sql20250205 = fsql.Select<OrderLine, Product>()
625638
.InnerJoin((l, p) => l.ProductId == p.ID)
626639
.GroupBy((l, p) => new { p.ID, ShopType = l.ShopType ?? 0 })
@@ -2997,6 +3010,13 @@ public override TestIdAndIdentity Deserialize(object value)
29973010
}
29983011
}
29993012
}
3013+
public class AppInfoEntity
3014+
{
3015+
[Column(IsPrimary = true, Name = "APP_ID")]
3016+
public string AppID { get; set; }
3017+
[Column(Name = "APP_NAME")]
3018+
public string AppName { get; set; }
3019+
}
30003020
public partial class OrderLine22x
30013021
{
30023022

FreeSql.DbContext/DbSet/DbSet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ public Dictionary<string, object[]> CompareState(TEntity newdata)
281281

282282
return _db.OrmOriginal.CompareEntityValueReturnColumns(_entityType, oldState.Value, newdata, false).ToDictionary(a => a, a => new object[]
283283
{
284-
_db.OrmOriginal.GetEntityValueWithPropertyName(_entityType, newdata, a),
285-
_db.OrmOriginal.GetEntityValueWithPropertyName(_entityType, oldState.Value, a)
284+
_db.OrmOriginal.GetEntityValueWithPropertyName(_entityType, newdata, _table.Columns[a].CsName),
285+
_db.OrmOriginal.GetEntityValueWithPropertyName(_entityType, oldState.Value, _table.Columns[a].CsName)
286286
});
287287
}
288288

FreeSql.DbContext/FreeSql.DbContext.xml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using FreeSql.DataAnnotations;
2+
using FreeSql.Internal;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.ComponentModel.DataAnnotations;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Xunit;
10+
11+
namespace FreeSql.Tests.DbContext2
12+
{
13+
public class CompareStateTest
14+
{
15+
[Fact]
16+
public void TestCompareState()
17+
{
18+
using (var fsql = g.CreateMemory())
19+
{
20+
fsql.Insert(new AppInfoEntity { AppID = "03DN8CW8", AppName = "app_01" }).ExecuteAffrows();
21+
var repo = fsql.GetRepository<AppInfoEntity>();
22+
23+
var appInfo = repo.Where(info => info.AppID == "03DN8CW8").First();
24+
appInfo = repo.Where(info => info.AppID == "03DN8CW8").First();
25+
var compareDic = new Dictionary<string, object[]>();
26+
var updateInfo = "";
27+
28+
repo.Attach(appInfo);
29+
appInfo.AppName = "测试";
30+
compareDic = repo.CompareState(appInfo);
31+
Console.WriteLine(appInfo.AppName);
32+
33+
}
34+
}
35+
36+
public class AppInfoEntity
37+
{
38+
[Column(IsPrimary = true, Name = "APP_ID")]
39+
public string AppID { get; set; }
40+
[Column(Name = "APP_NAME")]
41+
public string AppName { get; set; }
42+
}
43+
44+
}
45+
}

FreeSql/FreeSql.xml

Lines changed: 109 additions & 123 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)