- 增加 Repository/DbContext SaveMany 方法实现一对多,子数据的完整保存;

- 调整 SaveManyToMany 方法名为 SaveMany;
This commit is contained in:
28810
2019-11-21 16:42:20 +08:00
parent b5629b13a6
commit 04107d3d24
15 changed files with 150 additions and 109 deletions

View File

@ -158,14 +158,18 @@ namespace FreeSql
this.Set<TEntity>().AddOrUpdate(data);
}
/// <summary>
/// 保存实体的指定 ManyToMany 导航属性
/// 保存实体的指定 ManyToMany/OneToMany 导航属性(完整对比)<para></para>
/// 场景:在关闭级联保存功能之后,手工使用本方法<para></para>
/// 例子:保存商品的 OneToMany 集合属性SaveMany(goods, "Skus")<para></para>
/// 当 goods.Skus 为空(非null)时,会删除表中已存在的所有数据<para></para>
/// 当 goods.Skus 不为空(非null)时,添加/更新后,删除表中不存在 Skus 集合属性的所有记录
/// </summary>
/// <param name="data">实体对象</param>
/// <param name="propertyName">属性名</param>
public void SaveManyToMany<TEntity>(TEntity data, string propertyName) where TEntity : class
public void SaveMany<TEntity>(TEntity data, string propertyName) where TEntity : class
{
CheckEntityTypeOrThrow(typeof(TEntity));
this.Set<TEntity>().SaveManyToMany(data, propertyName);
this.Set<TEntity>().SaveMany(data, propertyName);
}
/// <summary>
@ -212,10 +216,10 @@ namespace FreeSql
CheckEntityTypeOrThrow(typeof(TEntity));
return this.Set<TEntity>().AddOrUpdateAsync(data);
}
public Task SaveManyToManyAsync<TEntity>(TEntity data, string propertyName) where TEntity : class
public Task SaveManyAsync<TEntity>(TEntity data, string propertyName) where TEntity : class
{
CheckEntityTypeOrThrow(typeof(TEntity));
return this.Set<TEntity>().SaveManyToManyAsync(data, propertyName);
return this.Set<TEntity>().SaveManyAsync(data, propertyName);
}
#endif
#endregion

View File

@ -9,9 +9,9 @@ namespace FreeSql
{
/// <summary>
/// 是否开启一对多,多对多级保存功能<para></para>
/// 是否开启一对多,多对多级保存功能<para></para>
/// <para></para>
/// 【一对多】模型下, 保存时可级保存实体的属性集合。出于使用安全考虑我们没做完整对比,只实现实体属性集合的添加或更新操作,所以不会删除实体属性集合的数据。<para></para>
/// 【一对多】模型下, 保存时可级保存实体的属性集合。出于使用安全考虑我们没做完整对比,只实现实体属性集合的添加或更新操作,所以不会删除实体属性集合的数据。<para></para>
/// 完整对比的功能使用起来太危险,试想下面的场景:<para></para>
/// - 保存的时候,实体的属性集合是空的,如何操作?记录全部删除?<para></para>
/// - 保存的时候,由于数据库中记录非常之多,那么只想保存子表的部分数据,或者只需要添加,如何操作?<para></para>