mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	- 移除 Repository SaveMany;
This commit is contained in:
		@@ -1,64 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Linq.Expressions;
 | 
			
		||||
 | 
			
		||||
namespace FreeSql
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    public interface IRepositoryUnitOfWork : IUnitOfWork
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 在工作单元内创建默认仓库类,工作单元下的仓储操作具有事务特点
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <typeparam name="TEntity"></typeparam>
 | 
			
		||||
        /// <typeparam name="TKey"></typeparam>
 | 
			
		||||
        /// <param name="filter">数据过滤 + 验证</param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        IBaseRepository<TEntity, TKey> GetRepository<TEntity, TKey>(Expression<Func<TEntity, bool>> filter = null) where TEntity : class;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 在工作单元内创建联合主键的仓储类,工作单元下的仓储操作具有事务特点
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <typeparam name="TEntity"></typeparam>
 | 
			
		||||
        /// <param name="filter">数据过滤 + 验证</param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        IBaseRepository<TEntity> GetRepository<TEntity>(Expression<Func<TEntity, bool>> filter = null) where TEntity : class;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 在工作单元内创建仓库类,工作单元下的仓储操作具有事务特点
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <typeparam name="TEntity"></typeparam>
 | 
			
		||||
        /// <param name="filter">数据过滤 + 验证</param>
 | 
			
		||||
        /// <param name="asTable">分表规则,参数:旧表名;返回:新表名 https://github.com/2881099/FreeSql/wiki/Repository</param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        IBaseRepository<TEntity, Guid> GetGuidRepository<TEntity>(Expression<Func<TEntity, bool>> filter = null, Func<string, string> asTable = null) where TEntity : class;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    class RepositoryUnitOfWork : UnitOfWork, IRepositoryUnitOfWork
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        public RepositoryUnitOfWork(IFreeSql fsql) : base(fsql)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IBaseRepository<TEntity, Guid> GetGuidRepository<TEntity>(Expression<Func<TEntity, bool>> filter = null, Func<string, string> asTable = null) where TEntity : class
 | 
			
		||||
        {
 | 
			
		||||
            var repo = new GuidRepository<TEntity>(_fsql, filter, asTable);
 | 
			
		||||
            repo.UnitOfWork = this;
 | 
			
		||||
            return repo;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IBaseRepository<TEntity, TKey> GetRepository<TEntity, TKey>(Expression<Func<TEntity, bool>> filter = null) where TEntity : class
 | 
			
		||||
        {
 | 
			
		||||
            var repo = new DefaultRepository<TEntity, TKey>(_fsql, filter);
 | 
			
		||||
            repo.UnitOfWork = this;
 | 
			
		||||
            return repo;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IBaseRepository<TEntity> GetRepository<TEntity>(Expression<Func<TEntity, bool>> filter = null) where TEntity : class
 | 
			
		||||
        {
 | 
			
		||||
            var repo = new DefaultRepository<TEntity, int>(_fsql, filter);
 | 
			
		||||
            repo.UnitOfWork = this;
 | 
			
		||||
            return repo;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -5,52 +5,24 @@ using System.Linq.Expressions;
 | 
			
		||||
 | 
			
		||||
partial class FreeSqlDbContextExtensions
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 返回默认仓库类
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <typeparam name="TEntity"></typeparam>
 | 
			
		||||
    /// <typeparam name="TKey"></typeparam>
 | 
			
		||||
    /// <param name="that"></param>
 | 
			
		||||
    /// <param name="filter">数据过滤 + 验证</param>
 | 
			
		||||
    /// <returns></returns>
 | 
			
		||||
    public static IBaseRepository<TEntity, TKey> GetRepository<TEntity, TKey>(this IFreeSql that, Expression<Func<TEntity, bool>> filter = null) where TEntity : class
 | 
			
		||||
    {
 | 
			
		||||
        return new DefaultRepository<TEntity, TKey>(that, filter);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 返回默认仓库类,适用联合主键的仓储类
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <typeparam name="TEntity"></typeparam>
 | 
			
		||||
    /// <param name="that"></param>
 | 
			
		||||
    /// <param name="filter">数据过滤 + 验证</param>
 | 
			
		||||
    /// <returns></returns>
 | 
			
		||||
    public static IBaseRepository<TEntity> GetRepository<TEntity>(this IFreeSql that, Expression<Func<TEntity, bool>> filter = null) where TEntity : class
 | 
			
		||||
    public static IBaseRepository<TEntity> GetRepository<TEntity>(this IFreeSql that) where TEntity : class
 | 
			
		||||
    {
 | 
			
		||||
        return new DefaultRepository<TEntity, int>(that, filter);
 | 
			
		||||
        return new DefaultRepository<TEntity, int>(that);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 返回仓库类
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <typeparam name="TEntity"></typeparam>
 | 
			
		||||
    /// <param name="that"></param>
 | 
			
		||||
    /// <param name="filter">数据过滤 + 验证</param>
 | 
			
		||||
    /// <param name="asTable">分表规则,参数:旧表名;返回:新表名 https://github.com/2881099/FreeSql/wiki/Repository</param>
 | 
			
		||||
    /// <returns></returns>
 | 
			
		||||
    public static IBaseRepository<TEntity, Guid> GetGuidRepository<TEntity>(this IFreeSql that, Expression<Func<TEntity, bool>> filter = null, Func<string, string> asTable = null) where TEntity : class
 | 
			
		||||
    {
 | 
			
		||||
        return new GuidRepository<TEntity>(that, filter, asTable);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 创建基于仓储功能的工作单元,务必使用 using 包含使用
 | 
			
		||||
    /// 创建基于工作单元,务必使用 using 包含使用
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="that"></param>
 | 
			
		||||
    /// <returns></returns>
 | 
			
		||||
    public static IRepositoryUnitOfWork CreateUnitOfWork(this IFreeSql that)
 | 
			
		||||
    public static IUnitOfWork CreateUnitOfWork(this IFreeSql that)
 | 
			
		||||
    {
 | 
			
		||||
        return new RepositoryUnitOfWork(that);
 | 
			
		||||
        return new UnitOfWork(that);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -19,10 +19,9 @@ namespace FreeSql
 | 
			
		||||
 | 
			
		||||
        internal Func<Type, string, string> _asTablePriv;
 | 
			
		||||
 | 
			
		||||
        protected BaseRepository(IFreeSql fsql, Expression<Func<TEntity, bool>> filter, Func<string, string> asTable = null)
 | 
			
		||||
        protected BaseRepository(IFreeSql fsql)
 | 
			
		||||
        {
 | 
			
		||||
            _ormScoped = DbContextScopedFreeSql.Create(fsql, () => _db, () => UnitOfWork);
 | 
			
		||||
            AsTable(asTable);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ~BaseRepository() => this.Dispose();
 | 
			
		||||
@@ -143,12 +142,6 @@ namespace FreeSql
 | 
			
		||||
            return entity;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public virtual void SaveMany(TEntity entity, string propertyName)
 | 
			
		||||
        {
 | 
			
		||||
            _dbset.SaveMany(entity, propertyName);
 | 
			
		||||
            _db.SaveChanges();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public virtual void BeginEdit(List<TEntity> data) => _dbset.BeginEdit(data);
 | 
			
		||||
        public virtual int EndEdit(List<TEntity> data = null)
 | 
			
		||||
        {
 | 
			
		||||
@@ -184,7 +177,7 @@ namespace FreeSql
 | 
			
		||||
    public abstract partial class BaseRepository<TEntity, TKey> : BaseRepository<TEntity>, IBaseRepository<TEntity, TKey>
 | 
			
		||||
        where TEntity : class
 | 
			
		||||
    {
 | 
			
		||||
        public BaseRepository(IFreeSql fsql, Expression<Func<TEntity, bool>> filter, Func<string, string> asTable = null) : base(fsql, filter, asTable) { }
 | 
			
		||||
        public BaseRepository(IFreeSql fsql) : base(fsql) { }
 | 
			
		||||
 | 
			
		||||
        TEntity CheckTKeyAndReturnIdEntity(TKey id)
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
@@ -68,12 +68,6 @@ namespace FreeSql
 | 
			
		||||
            await _db.SaveChangesAsync(cancellationToken);
 | 
			
		||||
            return entity;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public virtual async Task SaveManyAsync(TEntity entity, string propertyName, CancellationToken cancellationToken = default)
 | 
			
		||||
        {
 | 
			
		||||
            await _dbset.SaveManyAsync(entity, propertyName, cancellationToken);
 | 
			
		||||
            await _db.SaveChangesAsync(cancellationToken);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    partial class BaseRepository<TEntity, TKey>
 | 
			
		||||
 
 | 
			
		||||
@@ -3,21 +3,19 @@ using System.Linq.Expressions;
 | 
			
		||||
 | 
			
		||||
namespace FreeSql
 | 
			
		||||
{
 | 
			
		||||
    public class DefaultRepository<TEntity, TKey> : BaseRepository<TEntity, TKey> where TEntity : class
 | 
			
		||||
    class DefaultRepository<TEntity, TKey> : BaseRepository<TEntity, TKey> where TEntity : class
 | 
			
		||||
    {
 | 
			
		||||
        public DefaultRepository(IFreeSql fsql) : base(fsql, null, null) { }
 | 
			
		||||
        public DefaultRepository(IFreeSql fsql, Expression<Func<TEntity, bool>> filter) : base(fsql, filter, null) { }
 | 
			
		||||
        public DefaultRepository(IFreeSql fsql, UnitOfWorkManager uowManger) : base(uowManger?.Orm ?? fsql, null, null)
 | 
			
		||||
        public DefaultRepository(IFreeSql fsql) : base(fsql) { }
 | 
			
		||||
        public DefaultRepository(IFreeSql fsql, UnitOfWorkManager uowManger) : base(uowManger?.Orm ?? fsql)
 | 
			
		||||
        {
 | 
			
		||||
            uowManger?.Binding(this);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class GuidRepository<TEntity> : BaseRepository<TEntity, Guid> where TEntity : class
 | 
			
		||||
    class GuidRepository<TEntity> : BaseRepository<TEntity, Guid> where TEntity : class
 | 
			
		||||
    {
 | 
			
		||||
        public GuidRepository(IFreeSql fsql) : this(fsql, null, null) { }
 | 
			
		||||
        public GuidRepository(IFreeSql fsql, Expression<Func<TEntity, bool>> filter, Func<string, string> asTable) : base(fsql, filter, asTable) { }
 | 
			
		||||
        public GuidRepository(IFreeSql fsql, UnitOfWorkManager uowManger) : base(uowManger?.Orm ?? fsql, null, null)
 | 
			
		||||
        public GuidRepository(IFreeSql fsql) : base(fsql) { }
 | 
			
		||||
        public GuidRepository(IFreeSql fsql, UnitOfWorkManager uowManger) : base(uowManger?.Orm ?? fsql)
 | 
			
		||||
        {
 | 
			
		||||
            uowManger?.Binding(this);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -73,16 +73,6 @@ namespace FreeSql
 | 
			
		||||
        int Update(IEnumerable<TEntity> entitys);
 | 
			
		||||
 | 
			
		||||
        TEntity InsertOrUpdate(TEntity entity);
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 保存实体的指定 ManyToMany/OneToMany 导航属性(完整对比)<para></para>
 | 
			
		||||
        /// 场景:在关闭级联保存功能之后,手工使用本方法<para></para>
 | 
			
		||||
        /// 例子:保存商品的 OneToMany 集合属性,SaveMany(goods, "Skus")<para></para>
 | 
			
		||||
        /// 当 goods.Skus 为空(非null)时,会删除表中已存在的所有数据<para></para>
 | 
			
		||||
        /// 当 goods.Skus 不为空(非null)时,添加/更新后,删除表中不存在 Skus 集合属性的所有记录
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="entity">实体对象</param>
 | 
			
		||||
        /// <param name="propertyName">属性名</param>
 | 
			
		||||
        void SaveMany(TEntity entity, string propertyName);
 | 
			
		||||
 | 
			
		||||
        IUpdate<TEntity> UpdateDiy { get; }
 | 
			
		||||
 | 
			
		||||
@@ -121,7 +111,6 @@ namespace FreeSql
 | 
			
		||||
        Task<int> UpdateAsync(TEntity entity, CancellationToken cancellationToken = default);
 | 
			
		||||
        Task<int> UpdateAsync(IEnumerable<TEntity> entitys, CancellationToken cancellationToken = default);
 | 
			
		||||
        Task<TEntity> InsertOrUpdateAsync(TEntity entity, CancellationToken cancellationToken = default);
 | 
			
		||||
        Task SaveManyAsync(TEntity entity, string propertyName, CancellationToken cancellationToken = default);
 | 
			
		||||
 | 
			
		||||
        Task<int> DeleteAsync(TEntity entity, CancellationToken cancellationToken = default);
 | 
			
		||||
        Task<int> DeleteAsync(IEnumerable<TEntity> entitys, CancellationToken cancellationToken = default);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user