mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	- 增加 Repository/DbContext SaveMany 方法实现一对多,子数据的完整保存;
- 调整 SaveManyToMany 方法名为 SaveMany;
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user