Skip to content

Commit

Permalink
- 修复 聚合根仓储 InsertOrUpdate OneToMany 只插入一条记录的 bug;
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Feb 27, 2024
1 parent b18f9a5 commit c5b1488
Show file tree
Hide file tree
Showing 8 changed files with 779 additions and 308 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async Task<List<T1>> InsertWithinBoundaryStaticAsync<T1>(string boundaryName, IB
bool LocalCanInsert(Type entityType, object entity, bool isadd)
{
var stateKey = rootRepository.Orm.GetEntityKeyString(entityType, entity, false);
if (stateKey == null) return true;
if (string.IsNullOrEmpty(stateKey)) return true;
if (ignores.TryGetValue(entityType, out var stateKeys) == false)
{
if (isadd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static List<T1> InsertWithinBoundaryStatic<T1>(string boundaryName, IBaseReposit
bool LocalCanInsert(Type entityType, object entity, bool isadd)
{
var stateKey = rootRepository.Orm.GetEntityKeyString(entityType, entity, false);
if (stateKey == null) return true;
if (string.IsNullOrEmpty(stateKey)) return true;
if (ignores.TryGetValue(entityType, out var stateKeys) == false)
{
if (isadd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ void LocalCompareEntityValueCollection(Type elementType, IEnumerable collectionB
foreach (var item in collectionBefore)
{
var key = fsql.GetEntityKeyString(elementType, item, false);
if (key != null) dictBefore.Add(key, item);
if (!string.IsNullOrEmpty(key)) dictBefore.Add(key, item);
}
foreach (var item in collectionAfter)
{
var key = fsql.GetEntityKeyString(elementType, item, false);
if (key != null)
if (!string.IsNullOrEmpty(key))
{
if (dictAfter.ContainsKey(key) == false)
dictAfter.Add(key, item);
Expand Down
9 changes: 0 additions & 9 deletions FreeSql.DbContext/FreeSql.DbContext.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,38 @@ public OrderRepository(IFreeSql fsql, UnitOfWorkManager uowManager) : base(uowMa
public override ISelect<Order> Select => base.SelectDiy;
}

[Fact]
public void Test2()
{
using (var fsql = g.CreateMemory())
{
new OrderRepository(fsql, null);
var repo = fsql.GetAggregateRootRepository<Order>();

var order = new Order
{
Field2 = "field2",
Extdata = new OrderExt { Field3 = "field3" },
//Details = new List<OrderDetail>
//{
// new OrderDetail { Field4 = "field4_01", Extdata = new OrderDetailExt { Field5 = "field5_01" } },
// new OrderDetail { Field4 = "field4_02", Extdata = new OrderDetailExt { Field5 = "field5_02" } },
// new OrderDetail { Field4 = "field4_03", Extdata = new OrderDetailExt { Field5 = "field5_03" } },
//},
};
repo.Insert(order); //级联插入

var findOrder = repo.Select.Where(a => a.Id == order.Id).First();
findOrder.Details = new List<OrderDetail>
{
new OrderDetail { Field4 = "field4_01", Extdata = new OrderDetailExt { Field5 = "field5_01" } },
new OrderDetail { Field4 = "field4_02", Extdata = new OrderDetailExt { Field5 = "field5_02" } },
new OrderDetail { Field4 = "field4_03", Extdata = new OrderDetailExt { Field5 = "field5_03" } },
};
repo.InsertOrUpdate(findOrder);
}
}

[Fact]
public void Test1()
{
Expand Down Expand Up @@ -79,11 +111,11 @@ void LocalTest()
Field2 = "field2",
Extdata = new OrderExt { Field3 = "field3" },
Details = new List<OrderDetail>
{
new OrderDetail { Field4 = "field4_01", Extdata = new OrderDetailExt { Field5 = "field5_01" } },
new OrderDetail { Field4 = "field4_02", Extdata = new OrderDetailExt { Field5 = "field5_02" } },
new OrderDetail { Field4 = "field4_03", Extdata = new OrderDetailExt { Field5 = "field5_03" } },
},
{
new OrderDetail { Field4 = "field4_01", Extdata = new OrderDetailExt { Field5 = "field5_01" } },
new OrderDetail { Field4 = "field4_02", Extdata = new OrderDetailExt { Field5 = "field5_02" } },
new OrderDetail { Field4 = "field4_03", Extdata = new OrderDetailExt { Field5 = "field5_03" } },
},
Tags = fsql.Select<Tag>().Where(a => new[] { 1, 2, 3 }.Contains(a.Id)).ToList()
};
repo.Insert(order); //级联插入
Expand Down
Loading

0 comments on commit c5b1488

Please sign in to comment.