mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	- 调整 Repository 接口定义,合并为一个 IBaseRepository;
This commit is contained in:
		@@ -39,8 +39,7 @@ namespace restful.Controllers
 | 
				
			|||||||
            DefaultRepository<xxxx, int> repos21,
 | 
					            DefaultRepository<xxxx, int> repos21,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            BaseRepository<Song> repos3, BaseRepository<Song, int> repos4,
 | 
					            BaseRepository<Song> repos3, BaseRepository<Song, int> repos4,
 | 
				
			||||||
            IBasicRepository<Song> repos31, IBasicRepository<Song, int> repos41,
 | 
					            IBaseRepository<Song> repos31, IBaseRepository<Song, int> repos41,
 | 
				
			||||||
            IReadOnlyRepository<Song> repos311, IReadOnlyRepository<Song, int> repos411,
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            SongRepository reposSong
 | 
					            SongRepository reposSong
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -105,7 +105,7 @@ namespace FreeSql
 | 
				
			|||||||
            repo.Update(buf);
 | 
					            repo.Update(buf);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        T UpdateIsDelete<T>(bool value, Func<BaseRepository<TEntity>, List<TEntity>, T> func)
 | 
					        T UpdateIsDelete<T>(bool value, Func<IBaseRepository<TEntity>, List<TEntity>, T> func)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var childs = GetAllChilds();
 | 
					            var childs = GetAllChilds();
 | 
				
			||||||
            childs.Add(this as TEntity);
 | 
					            childs.Add(this as TEntity);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -110,13 +110,6 @@
 | 
				
			|||||||
            清空状态数据
 | 
					            清空状态数据
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
        <member name="M:FreeSql.DbSet`1.RemoveAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
 | 
					 | 
				
			||||||
            <summary>
 | 
					 | 
				
			||||||
            根据 lambda 条件删除数据
 | 
					 | 
				
			||||||
            </summary>
 | 
					 | 
				
			||||||
            <param name="predicate"></param>
 | 
					 | 
				
			||||||
            <returns></returns>
 | 
					 | 
				
			||||||
        </member>
 | 
					 | 
				
			||||||
        <member name="M:FreeSql.DbSet`1.Add(`0)">
 | 
					        <member name="M:FreeSql.DbSet`1.Add(`0)">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            添加
 | 
					            添加
 | 
				
			||||||
@@ -218,29 +211,35 @@
 | 
				
			|||||||
            <param name="entityType"></param>
 | 
					            <param name="entityType"></param>
 | 
				
			||||||
            <returns></returns>
 | 
					            <returns></returns>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:FreeSql.IBaseRepository.AsTable(System.Func{System.String,System.String})">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            分表规则,参数:旧表名;返回:新表名 https://github.com/2881099/FreeSql/wiki/Repository
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <param name="rule"></param>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
        <member name="P:FreeSql.IBaseRepository.DbContextOptions">
 | 
					        <member name="P:FreeSql.IBaseRepository.DbContextOptions">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            设置 DbContext 选项
 | 
					            设置 DbContext 选项
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
        <member name="M:FreeSql.IBasicRepository`1.FlushState">
 | 
					        <member name="M:FreeSql.IBaseRepository`1.FlushState">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            清空状态数据
 | 
					            清空状态数据
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
        <member name="M:FreeSql.IBasicRepository`1.Attach(`0)">
 | 
					        <member name="M:FreeSql.IBaseRepository`1.Attach(`0)">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            附加实体,可用于不查询就更新或删除
 | 
					            附加实体,可用于不查询就更新或删除
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
            <param name="entity"></param>
 | 
					            <param name="entity"></param>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
        <member name="M:FreeSql.IBasicRepository`1.AttachOnlyPrimary(`0)">
 | 
					        <member name="M:FreeSql.IBaseRepository`1.AttachOnlyPrimary(`0)">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            附加实体,并且只附加主键值,可用于不更新属性值为null或默认值的字段
 | 
					            附加实体,并且只附加主键值,可用于不更新属性值为null或默认值的字段
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
            <param name="data"></param>
 | 
					            <param name="data"></param>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
        <member name="M:FreeSql.IBasicRepository`1.SaveMany(`0,System.String)">
 | 
					        <member name="M:FreeSql.IBaseRepository`1.SaveMany(`0,System.String)">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            保存实体的指定 ManyToMany/OneToMany 导航属性(完整对比)<para></para>
 | 
					            保存实体的指定 ManyToMany/OneToMany 导航属性(完整对比)<para></para>
 | 
				
			||||||
            场景:在关闭级联保存功能之后,手工使用本方法<para></para>
 | 
					            场景:在关闭级联保存功能之后,手工使用本方法<para></para>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,6 @@ namespace FreeSql
 | 
				
			|||||||
            _repo = repo;
 | 
					            _repo = repo;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        static ConcurrentDictionary<Type, FieldInfo> _dicGetRepositoryDbField = new ConcurrentDictionary<Type, FieldInfo>();
 | 
					        static ConcurrentDictionary<Type, FieldInfo> _dicGetRepositoryDbField = new ConcurrentDictionary<Type, FieldInfo>();
 | 
				
			||||||
        static FieldInfo GetRepositoryDbField(Type type) => _dicGetRepositoryDbField.GetOrAdd(type, tp => typeof(BaseRepository<,>).MakeGenericType(tp, typeof(int)).GetField("_dbPriv", BindingFlags.Instance | BindingFlags.NonPublic));
 | 
					        static FieldInfo GetRepositoryDbField(Type type) => _dicGetRepositoryDbField.GetOrAdd(type, tp => typeof(BaseRepository<,>).MakeGenericType(tp, typeof(int)).GetField("_dbPriv", BindingFlags.Instance | BindingFlags.NonPublic));
 | 
				
			||||||
        public override IDbSet Set(Type entityType)
 | 
					        public override IDbSet Set(Type entityType)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ namespace FreeSql
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            var filters = (_repo.DataFilter as DataFilter<TEntity>)._filters.Where(a => a.Value.IsEnabled == true);
 | 
					            var filters = (_repo.DataFilter as DataFilter<TEntity>)._filters.Where(a => a.Value.IsEnabled == true);
 | 
				
			||||||
            foreach (var filter in filters) select.Where(filter.Value.Expression);
 | 
					            foreach (var filter in filters) select.Where(filter.Value.Expression);
 | 
				
			||||||
            return select.AsTable(_repo.AsTableSelectInternal);
 | 
					            return select.AsTable(_repo.AsTableSelectValueInternal);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        internal ISelect<TEntity> OrmSelectInternal(object dywhere) => OrmSelect(dywhere);
 | 
					        internal ISelect<TEntity> OrmSelectInternal(object dywhere) => OrmSelect(dywhere);
 | 
				
			||||||
        protected override IUpdate<TEntity> OrmUpdate(IEnumerable<TEntity> entitys)
 | 
					        protected override IUpdate<TEntity> OrmUpdate(IEnumerable<TEntity> entitys)
 | 
				
			||||||
@@ -37,7 +37,7 @@ namespace FreeSql
 | 
				
			|||||||
                            throw new Exception($"FreeSql.Repository Update 失败,因为设置了过滤器 {filter.Key}: {filter.Value.Expression},更新的数据不符合 {_db.Orm.GetEntityString(_entityType, entity)}");
 | 
					                            throw new Exception($"FreeSql.Repository Update 失败,因为设置了过滤器 {filter.Key}: {filter.Value.Expression},更新的数据不符合 {_db.Orm.GetEntityString(_entityType, entity)}");
 | 
				
			||||||
                update.Where(filter.Value.Expression);
 | 
					                update.Where(filter.Value.Expression);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return update.AsTable(_repo.AsTableInternal);
 | 
					            return update.AsTable(_repo.AsTableValueInternal);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        internal IUpdate<TEntity> OrmUpdateInternal(IEnumerable<TEntity> entitys) => OrmUpdate(entitys);
 | 
					        internal IUpdate<TEntity> OrmUpdateInternal(IEnumerable<TEntity> entitys) => OrmUpdate(entitys);
 | 
				
			||||||
        protected override IDelete<TEntity> OrmDelete(object dywhere)
 | 
					        protected override IDelete<TEntity> OrmDelete(object dywhere)
 | 
				
			||||||
@@ -45,7 +45,7 @@ namespace FreeSql
 | 
				
			|||||||
            var delete = base.OrmDelete(dywhere);
 | 
					            var delete = base.OrmDelete(dywhere);
 | 
				
			||||||
            var filters = (_repo.DataFilter as DataFilter<TEntity>)._filters.Where(a => a.Value.IsEnabled == true);
 | 
					            var filters = (_repo.DataFilter as DataFilter<TEntity>)._filters.Where(a => a.Value.IsEnabled == true);
 | 
				
			||||||
            foreach (var filter in filters) delete.Where(filter.Value.Expression);
 | 
					            foreach (var filter in filters) delete.Where(filter.Value.Expression);
 | 
				
			||||||
            return delete.AsTable(_repo.AsTableInternal);
 | 
					            return delete.AsTable(_repo.AsTableValueInternal);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        internal IDelete<TEntity> OrmDeleteInternal(object dywhere) => OrmDelete(dywhere);
 | 
					        internal IDelete<TEntity> OrmDeleteInternal(object dywhere) => OrmDelete(dywhere);
 | 
				
			||||||
        protected override IInsert<TEntity> OrmInsert(TEntity entity) => OrmInsert(new[] { entity });
 | 
					        protected override IInsert<TEntity> OrmInsert(TEntity entity) => OrmInsert(new[] { entity });
 | 
				
			||||||
@@ -60,7 +60,7 @@ namespace FreeSql
 | 
				
			|||||||
                        if (filter.Value.ExpressionDelegate?.Invoke(entity) == false)
 | 
					                        if (filter.Value.ExpressionDelegate?.Invoke(entity) == false)
 | 
				
			||||||
                            throw new Exception($"FreeSql.Repository Insert 失败,因为设置了过滤器 {filter.Key}: {filter.Value.Expression},插入的数据不符合 {_db.Orm.GetEntityString(_entityType, entity)}");
 | 
					                            throw new Exception($"FreeSql.Repository Insert 失败,因为设置了过滤器 {filter.Key}: {filter.Value.Expression},插入的数据不符合 {_db.Orm.GetEntityString(_entityType, entity)}");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return insert.AsTable(_repo.AsTableInternal);
 | 
					            return insert.AsTable(_repo.AsTableValueInternal);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        internal IInsert<TEntity> OrmInsertInternal(TEntity entity) => OrmInsert(entity);
 | 
					        internal IInsert<TEntity> OrmInsertInternal(TEntity entity) => OrmInsert(entity);
 | 
				
			||||||
        internal IInsert<TEntity> OrmInsertInternal(IEnumerable<TEntity> entitys) => OrmInsert(entitys);
 | 
					        internal IInsert<TEntity> OrmInsertInternal(IEnumerable<TEntity> entitys) => OrmInsert(entitys);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,7 +13,7 @@ namespace FreeSql
 | 
				
			|||||||
        /// <typeparam name="TKey"></typeparam>
 | 
					        /// <typeparam name="TKey"></typeparam>
 | 
				
			||||||
        /// <param name="filter">数据过滤 + 验证</param>
 | 
					        /// <param name="filter">数据过滤 + 验证</param>
 | 
				
			||||||
        /// <returns></returns>
 | 
					        /// <returns></returns>
 | 
				
			||||||
        DefaultRepository<TEntity, TKey> GetRepository<TEntity, TKey>(Expression<Func<TEntity, bool>> filter = null) where TEntity : class;
 | 
					        IBaseRepository<TEntity, TKey> GetRepository<TEntity, TKey>(Expression<Func<TEntity, bool>> filter = null) where TEntity : class;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 在工作单元内创建联合主键的仓储类,工作单元下的仓储操作具有事务特点
 | 
					        /// 在工作单元内创建联合主键的仓储类,工作单元下的仓储操作具有事务特点
 | 
				
			||||||
@@ -21,7 +21,7 @@ namespace FreeSql
 | 
				
			|||||||
        /// <typeparam name="TEntity"></typeparam>
 | 
					        /// <typeparam name="TEntity"></typeparam>
 | 
				
			||||||
        /// <param name="filter">数据过滤 + 验证</param>
 | 
					        /// <param name="filter">数据过滤 + 验证</param>
 | 
				
			||||||
        /// <returns></returns>
 | 
					        /// <returns></returns>
 | 
				
			||||||
        BaseRepository<TEntity> GetRepository<TEntity>(Expression<Func<TEntity, bool>> filter = null) where TEntity : class;
 | 
					        IBaseRepository<TEntity> GetRepository<TEntity>(Expression<Func<TEntity, bool>> filter = null) where TEntity : class;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 在工作单元内创建仓库类,工作单元下的仓储操作具有事务特点
 | 
					        /// 在工作单元内创建仓库类,工作单元下的仓储操作具有事务特点
 | 
				
			||||||
@@ -30,7 +30,7 @@ namespace FreeSql
 | 
				
			|||||||
        /// <param name="filter">数据过滤 + 验证</param>
 | 
					        /// <param name="filter">数据过滤 + 验证</param>
 | 
				
			||||||
        /// <param name="asTable">分表规则,参数:旧表名;返回:新表名 https://github.com/2881099/FreeSql/wiki/Repository</param>
 | 
					        /// <param name="asTable">分表规则,参数:旧表名;返回:新表名 https://github.com/2881099/FreeSql/wiki/Repository</param>
 | 
				
			||||||
        /// <returns></returns>
 | 
					        /// <returns></returns>
 | 
				
			||||||
        GuidRepository<TEntity> GetGuidRepository<TEntity>(Expression<Func<TEntity, bool>> filter = null, Func<string, string> asTable = null) where TEntity : class;
 | 
					        IBaseRepository<TEntity, Guid> GetGuidRepository<TEntity>(Expression<Func<TEntity, bool>> filter = null, Func<string, string> asTable = null) where TEntity : class;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class RepositoryUnitOfWork : UnitOfWork, IRepositoryUnitOfWork
 | 
					    class RepositoryUnitOfWork : UnitOfWork, IRepositoryUnitOfWork
 | 
				
			||||||
@@ -40,21 +40,21 @@ namespace FreeSql
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public GuidRepository<TEntity> GetGuidRepository<TEntity>(Expression<Func<TEntity, bool>> filter = null, Func<string, string> asTable = null) where TEntity : class
 | 
					        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);
 | 
					            var repo = new GuidRepository<TEntity>(_fsql, filter, asTable);
 | 
				
			||||||
            repo.UnitOfWork = this;
 | 
					            repo.UnitOfWork = this;
 | 
				
			||||||
            return repo;
 | 
					            return repo;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public DefaultRepository<TEntity, TKey> GetRepository<TEntity, TKey>(Expression<Func<TEntity, bool>> filter = null) where TEntity : class
 | 
					        public IBaseRepository<TEntity, TKey> GetRepository<TEntity, TKey>(Expression<Func<TEntity, bool>> filter = null) where TEntity : class
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var repo = new DefaultRepository<TEntity, TKey>(_fsql, filter);
 | 
					            var repo = new DefaultRepository<TEntity, TKey>(_fsql, filter);
 | 
				
			||||||
            repo.UnitOfWork = this;
 | 
					            repo.UnitOfWork = this;
 | 
				
			||||||
            return repo;
 | 
					            return repo;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public BaseRepository<TEntity> GetRepository<TEntity>(Expression<Func<TEntity, bool>> filter = null) where TEntity : class
 | 
					        public IBaseRepository<TEntity> GetRepository<TEntity>(Expression<Func<TEntity, bool>> filter = null) where TEntity : class
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var repo = new DefaultRepository<TEntity, int>(_fsql, filter);
 | 
					            var repo = new DefaultRepository<TEntity, int>(_fsql, filter);
 | 
				
			||||||
            repo.UnitOfWork = this;
 | 
					            repo.UnitOfWork = this;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,29 +1,36 @@
 | 
				
			|||||||
#if netcoreapp
 | 
					#if netcoreapp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using System;
 | 
					 | 
				
			||||||
using System.Reflection;
 | 
					 | 
				
			||||||
using System.Linq;
 | 
					 | 
				
			||||||
using Microsoft.Extensions.DependencyInjection;
 | 
					using Microsoft.Extensions.DependencyInjection;
 | 
				
			||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Reflection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace FreeSql
 | 
					namespace FreeSql
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public static class FreeSqlRepositoryDependencyInjection
 | 
					    public static class FreeSqlRepositoryDependencyInjection
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 批量注入 Repository,可以参考代码自行调整
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="services"></param>
 | 
				
			||||||
 | 
					        /// <param name="globalDataFilter"></param>
 | 
				
			||||||
 | 
					        /// <param name="assemblies"></param>
 | 
				
			||||||
 | 
					        /// <returns></returns>
 | 
				
			||||||
        public static IServiceCollection AddFreeRepository(this IServiceCollection services, Action<FluentDataFilter> globalDataFilter = null, params Assembly[] assemblies)
 | 
					        public static IServiceCollection AddFreeRepository(this IServiceCollection services, Action<FluentDataFilter> globalDataFilter = null, params Assembly[] assemblies)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            if (globalDataFilter != null)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                DataFilterUtil._globalDataFilter = globalDataFilter;
 | 
				
			||||||
 | 
					                //如果看到了这里的代码,想自己调整,但因为 _globalDataFilter 是内部属性,无法修改?
 | 
				
			||||||
 | 
					                //请考虑改用 fsql.GlobalFilter.Apply
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            DataFilterUtil._globalDataFilter = globalDataFilter;
 | 
					            services.AddScoped(typeof(IBaseRepository<>), typeof(GuidRepository<>));
 | 
				
			||||||
 | 
					 | 
				
			||||||
            services.AddScoped(typeof(IReadOnlyRepository<>), typeof(GuidRepository<>));
 | 
					 | 
				
			||||||
            services.AddScoped(typeof(IBasicRepository<>), typeof(GuidRepository<>));
 | 
					 | 
				
			||||||
            services.AddScoped(typeof(BaseRepository<>), typeof(GuidRepository<>));
 | 
					            services.AddScoped(typeof(BaseRepository<>), typeof(GuidRepository<>));
 | 
				
			||||||
            services.AddScoped(typeof(GuidRepository<>));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            services.AddScoped(typeof(IReadOnlyRepository<,>), typeof(DefaultRepository<,>));
 | 
					            services.AddScoped(typeof(IBaseRepository<,>), typeof(DefaultRepository<,>));
 | 
				
			||||||
            services.AddScoped(typeof(IBasicRepository<,>), typeof(DefaultRepository<,>));
 | 
					 | 
				
			||||||
            services.AddScoped(typeof(BaseRepository<,>), typeof(DefaultRepository<,>));
 | 
					            services.AddScoped(typeof(BaseRepository<,>), typeof(DefaultRepository<,>));
 | 
				
			||||||
            services.AddScoped(typeof(DefaultRepository<,>));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (assemblies?.Any() == true)
 | 
					            if (assemblies?.Any() == true)
 | 
				
			||||||
                foreach (var asse in assemblies)
 | 
					                foreach (var asse in assemblies)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
using FreeSql;
 | 
					using FreeSql;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Linq.Expressions;
 | 
					 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Linq.Expressions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public static class FreeSqlRepositoryExtensions
 | 
					public static class FreeSqlRepositoryExtensions
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -14,7 +14,7 @@ public static class FreeSqlRepositoryExtensions
 | 
				
			|||||||
    /// <param name="that"></param>
 | 
					    /// <param name="that"></param>
 | 
				
			||||||
    /// <param name="filter">数据过滤 + 验证</param>
 | 
					    /// <param name="filter">数据过滤 + 验证</param>
 | 
				
			||||||
    /// <returns></returns>
 | 
					    /// <returns></returns>
 | 
				
			||||||
    public static DefaultRepository<TEntity, TKey> GetRepository<TEntity, TKey>(this IFreeSql that, Expression<Func<TEntity, bool>> filter = null) where TEntity : class
 | 
					    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);
 | 
					        return new DefaultRepository<TEntity, TKey>(that, filter);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -26,7 +26,7 @@ public static class FreeSqlRepositoryExtensions
 | 
				
			|||||||
    /// <param name="that"></param>
 | 
					    /// <param name="that"></param>
 | 
				
			||||||
    /// <param name="filter">数据过滤 + 验证</param>
 | 
					    /// <param name="filter">数据过滤 + 验证</param>
 | 
				
			||||||
    /// <returns></returns>
 | 
					    /// <returns></returns>
 | 
				
			||||||
    public static BaseRepository<TEntity> GetRepository<TEntity>(this IFreeSql that, Expression<Func<TEntity, bool>> filter = null) where TEntity : class
 | 
					    public static IBaseRepository<TEntity> GetRepository<TEntity>(this IFreeSql that, Expression<Func<TEntity, bool>> filter = null) where TEntity : class
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return new DefaultRepository<TEntity, int>(that, filter);
 | 
					        return new DefaultRepository<TEntity, int>(that, filter);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -39,26 +39,11 @@ public static class FreeSqlRepositoryExtensions
 | 
				
			|||||||
    /// <param name="filter">数据过滤 + 验证</param>
 | 
					    /// <param name="filter">数据过滤 + 验证</param>
 | 
				
			||||||
    /// <param name="asTable">分表规则,参数:旧表名;返回:新表名 https://github.com/2881099/FreeSql/wiki/Repository</param>
 | 
					    /// <param name="asTable">分表规则,参数:旧表名;返回:新表名 https://github.com/2881099/FreeSql/wiki/Repository</param>
 | 
				
			||||||
    /// <returns></returns>
 | 
					    /// <returns></returns>
 | 
				
			||||||
    public static GuidRepository<TEntity> GetGuidRepository<TEntity>(this IFreeSql that, Expression<Func<TEntity, bool>> filter = null, Func<string, string> asTable = null) where TEntity : class
 | 
					    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);
 | 
					        return new GuidRepository<TEntity>(that, filter, asTable);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ///// <summary>
 | 
					 | 
				
			||||||
    ///// 合并两个仓储的设置(过滤+分表),以便查询
 | 
					 | 
				
			||||||
    ///// </summary>
 | 
					 | 
				
			||||||
    ///// <typeparam name="TEntity"></typeparam>
 | 
					 | 
				
			||||||
    ///// <typeparam name="T2"></typeparam>
 | 
					 | 
				
			||||||
    ///// <param name="that"></param>
 | 
					 | 
				
			||||||
    ///// <param name="repos"></param>
 | 
					 | 
				
			||||||
    ///// <returns></returns>
 | 
					 | 
				
			||||||
    //public static ISelect<TEntity> FromRepository<TEntity, T2>(this ISelect<TEntity> that, BaseRepository<T2> repos) where TEntity : class where T2 : class
 | 
					 | 
				
			||||||
    //{
 | 
					 | 
				
			||||||
    //    var filters = (repos.DataFilter as DataFilter<T2>)._filters.Where(a => a.Value.IsEnabled == true);
 | 
					 | 
				
			||||||
    //    foreach (var filter in filters) that.Where<T2>(filter.Value.Expression);
 | 
					 | 
				
			||||||
    //    return that.AsTable(repos.AsTableSelectInternal);
 | 
					 | 
				
			||||||
    //}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
    /// 创建基于仓储功能的工作单元,务必使用 using 包含使用
 | 
					    /// 创建基于仓储功能的工作单元,务必使用 using 包含使用
 | 
				
			||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,19 +18,8 @@ namespace FreeSql
 | 
				
			|||||||
        internal RepositoryDbSet<TEntity> _dbset => _dbsetPriv ?? (_dbsetPriv = _db.Set<TEntity>() as RepositoryDbSet<TEntity>);
 | 
					        internal RepositoryDbSet<TEntity> _dbset => _dbsetPriv ?? (_dbsetPriv = _db.Set<TEntity>() as RepositoryDbSet<TEntity>);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public IDataFilter<TEntity> DataFilter { get; } = new DataFilter<TEntity>();
 | 
					        public IDataFilter<TEntity> DataFilter { get; } = new DataFilter<TEntity>();
 | 
				
			||||||
        Func<string, string> _asTableVal;
 | 
					        internal Func<string, string> AsTableValueInternal { get; private set; }
 | 
				
			||||||
        protected Func<string, string> AsTable
 | 
					        internal Func<Type, string, string> AsTableSelectValueInternal { get; private set; }
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            get => _asTableVal;
 | 
					 | 
				
			||||||
            set
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                _asTableVal = value;
 | 
					 | 
				
			||||||
                AsTableSelect = value == null ? null : new Func<Type, string, string>((a, b) => a == EntityType ? value(b) : null);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        internal Func<string, string> AsTableInternal => AsTable;
 | 
					 | 
				
			||||||
        protected Func<Type, string, string> AsTableSelect { get; private set; }
 | 
					 | 
				
			||||||
        internal Func<Type, string, string> AsTableSelectInternal => AsTableSelect;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        protected void ApplyDataFilter(string name, Expression<Func<TEntity, bool>> exp) => DataFilter.Apply(name, exp);
 | 
					        protected void ApplyDataFilter(string name, Expression<Func<TEntity, bool>> exp) => DataFilter.Apply(name, exp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -39,7 +28,7 @@ namespace FreeSql
 | 
				
			|||||||
            Orm = fsql;
 | 
					            Orm = fsql;
 | 
				
			||||||
            DataFilterUtil.SetRepositoryDataFilter(this, null);
 | 
					            DataFilterUtil.SetRepositoryDataFilter(this, null);
 | 
				
			||||||
            DataFilter.Apply("", filter);
 | 
					            DataFilter.Apply("", filter);
 | 
				
			||||||
            AsTable = asTable;
 | 
					            AsTable(asTable);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ~BaseRepository() => this.Dispose();
 | 
					        ~BaseRepository() => this.Dispose();
 | 
				
			||||||
@@ -60,6 +49,11 @@ namespace FreeSql
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        public Type EntityType => _dbsetPriv?.EntityType ?? typeof(TEntity);
 | 
					        public Type EntityType => _dbsetPriv?.EntityType ?? typeof(TEntity);
 | 
				
			||||||
        public void AsType(Type entityType) => _dbset.AsType(entityType);
 | 
					        public void AsType(Type entityType) => _dbset.AsType(entityType);
 | 
				
			||||||
 | 
					        public void AsTable(Func<string, string> rule)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            AsTableValueInternal = rule;
 | 
				
			||||||
 | 
					            AsTableSelectValueInternal = rule == null ? null : new Func<Type, string, string>((a, b) => a == EntityType ? rule(b) : null);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        public DbContextOptions DbContextOptions { get => _db.Options; set => _db.Options = value; }
 | 
					        public DbContextOptions DbContextOptions { get => _db.Options; set => _db.Options = value; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public IFreeSql Orm { get; private set; }
 | 
					        public IFreeSql Orm { get; private set; }
 | 
				
			||||||
@@ -125,7 +119,7 @@ namespace FreeSql
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public void Attach(TEntity data) => _db.Attach(data);
 | 
					        public void Attach(TEntity data) => _db.Attach(data);
 | 
				
			||||||
        public void Attach(IEnumerable<TEntity> data) => _db.AttachRange(data);
 | 
					        public void Attach(IEnumerable<TEntity> data) => _db.AttachRange(data);
 | 
				
			||||||
        public IBasicRepository<TEntity> AttachOnlyPrimary(TEntity data)
 | 
					        public IBaseRepository<TEntity> AttachOnlyPrimary(TEntity data)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            _db.AttachOnlyPrimary(data);
 | 
					            _db.AttachOnlyPrimary(data);
 | 
				
			||||||
            return this;
 | 
					            return this;
 | 
				
			||||||
@@ -149,10 +143,7 @@ namespace FreeSql
 | 
				
			|||||||
    public abstract partial class BaseRepository<TEntity, TKey> : BaseRepository<TEntity>, IBaseRepository<TEntity, TKey>
 | 
					    public abstract partial class BaseRepository<TEntity, TKey> : BaseRepository<TEntity>, IBaseRepository<TEntity, TKey>
 | 
				
			||||||
        where TEntity : class
 | 
					        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, Expression<Func<TEntity, bool>> filter, Func<string, string> asTable = null) : base(fsql, filter, asTable)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        TEntity CheckTKeyAndReturnIdEntity(TKey id)
 | 
					        TEntity CheckTKeyAndReturnIdEntity(TKey id)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
@@ -167,9 +158,7 @@ namespace FreeSql
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public int Delete(TKey id) => Delete(CheckTKeyAndReturnIdEntity(id));
 | 
					        public int Delete(TKey id) => Delete(CheckTKeyAndReturnIdEntity(id));
 | 
				
			||||||
 | 
					 | 
				
			||||||
        public TEntity Find(TKey id) => _dbset.OrmSelectInternal(CheckTKeyAndReturnIdEntity(id)).ToOne();
 | 
					        public TEntity Find(TKey id) => _dbset.OrmSelectInternal(CheckTKeyAndReturnIdEntity(id)).ToOne();
 | 
				
			||||||
 | 
					 | 
				
			||||||
        public TEntity Get(TKey id) => Find(id);
 | 
					        public TEntity Get(TKey id) => Find(id);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -73,11 +73,8 @@ namespace FreeSql
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    partial class BaseRepository<TEntity, TKey>
 | 
					    partial class BaseRepository<TEntity, TKey>
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        public Task<int> DeleteAsync(TKey id) => DeleteAsync(CheckTKeyAndReturnIdEntity(id));
 | 
					        public Task<int> DeleteAsync(TKey id) => DeleteAsync(CheckTKeyAndReturnIdEntity(id));
 | 
				
			||||||
 | 
					 | 
				
			||||||
        public Task<TEntity> FindAsync(TKey id) => _dbset.OrmSelectInternal(CheckTKeyAndReturnIdEntity(id)).ToOneAsync();
 | 
					        public Task<TEntity> FindAsync(TKey id) => _dbset.OrmSelectInternal(CheckTKeyAndReturnIdEntity(id)).ToOneAsync();
 | 
				
			||||||
 | 
					 | 
				
			||||||
        public Task<TEntity> GetAsync(TKey id) => FindAsync(id);
 | 
					        public Task<TEntity> GetAsync(TKey id) => FindAsync(id);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,18 +3,15 @@ using System.Linq.Expressions;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace FreeSql
 | 
					namespace FreeSql
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public class DefaultRepository<TEntity, TKey> :
 | 
					    public class DefaultRepository<TEntity, TKey> : BaseRepository<TEntity, TKey> where TEntity : class
 | 
				
			||||||
        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) : base(fsql, null, null)
 | 
					    public 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 DefaultRepository(IFreeSql fsql, Expression<Func<TEntity, bool>> filter) : base(fsql, filter, null)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,19 +0,0 @@
 | 
				
			|||||||
using System;
 | 
					 | 
				
			||||||
using System.Linq.Expressions;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace FreeSql
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    public 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)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,4 +1,5 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using System.Linq.Expressions;
 | 
					using System.Linq.Expressions;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -17,6 +18,11 @@ namespace FreeSql
 | 
				
			|||||||
        /// <param name="entityType"></param>
 | 
					        /// <param name="entityType"></param>
 | 
				
			||||||
        /// <returns></returns>
 | 
					        /// <returns></returns>
 | 
				
			||||||
        void AsType(Type entityType);
 | 
					        void AsType(Type entityType);
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 分表规则,参数:旧表名;返回:新表名 https://github.com/2881099/FreeSql/wiki/Repository
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="rule"></param>
 | 
				
			||||||
 | 
					        void AsTable(Func<string, string> rule);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 设置 DbContext 选项
 | 
					        /// 设置 DbContext 选项
 | 
				
			||||||
@@ -24,19 +30,83 @@ namespace FreeSql
 | 
				
			|||||||
        DbContextOptions DbContextOptions { get; set; }
 | 
					        DbContextOptions DbContextOptions { get; set; }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public interface IBaseRepository<TEntity> : IReadOnlyRepository<TEntity>, IBasicRepository<TEntity>
 | 
					    public interface IBaseRepository<TEntity> : IBaseRepository
 | 
				
			||||||
        where TEntity : class
 | 
					        where TEntity : class
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        IDataFilter<TEntity> DataFilter { get; }
 | 
				
			||||||
 | 
					        ISelect<TEntity> Select { get; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ISelect<TEntity> Where(Expression<Func<TEntity, bool>> exp);
 | 
				
			||||||
 | 
					        ISelect<TEntity> WhereIf(bool condition, Expression<Func<TEntity, bool>> exp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        TEntity Insert(TEntity entity);
 | 
				
			||||||
 | 
					        List<TEntity> Insert(IEnumerable<TEntity> entitys);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 清空状态数据
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        void FlushState();
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 附加实体,可用于不查询就更新或删除
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="entity"></param>
 | 
				
			||||||
 | 
					        void Attach(TEntity entity);
 | 
				
			||||||
 | 
					        void Attach(IEnumerable<TEntity> entity);
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 附加实体,并且只附加主键值,可用于不更新属性值为null或默认值的字段
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="data"></param>
 | 
				
			||||||
 | 
					        IBaseRepository<TEntity> AttachOnlyPrimary(TEntity data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        int Update(TEntity entity);
 | 
				
			||||||
 | 
					        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; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        int Delete(TEntity entity);
 | 
				
			||||||
 | 
					        int Delete(IEnumerable<TEntity> entitys);
 | 
				
			||||||
        int Delete(Expression<Func<TEntity, bool>> predicate);
 | 
					        int Delete(Expression<Func<TEntity, bool>> predicate);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if net40
 | 
					#if net40
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
 | 
					        Task<TEntity> InsertAsync(TEntity entity);
 | 
				
			||||||
 | 
					        Task<List<TEntity>> InsertAsync(IEnumerable<TEntity> entitys);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Task<int> UpdateAsync(TEntity entity);
 | 
				
			||||||
 | 
					        Task<int> UpdateAsync(IEnumerable<TEntity> entitys);
 | 
				
			||||||
 | 
					        Task<TEntity> InsertOrUpdateAsync(TEntity entity);
 | 
				
			||||||
 | 
					        Task SaveManyAsync(TEntity entity, string propertyName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Task<int> DeleteAsync(TEntity entity);
 | 
				
			||||||
 | 
					        Task<int> DeleteAsync(IEnumerable<TEntity> entitys);
 | 
				
			||||||
        Task<int> DeleteAsync(Expression<Func<TEntity, bool>> predicate);
 | 
					        Task<int> DeleteAsync(Expression<Func<TEntity, bool>> predicate);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public interface IBaseRepository<TEntity, TKey> : IBaseRepository<TEntity>, IReadOnlyRepository<TEntity, TKey>, IBasicRepository<TEntity, TKey>
 | 
					    public interface IBaseRepository<TEntity, TKey> : IBaseRepository<TEntity>
 | 
				
			||||||
        where TEntity : class
 | 
					        where TEntity : class
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        TEntity Get(TKey id);
 | 
				
			||||||
 | 
					        TEntity Find(TKey id);
 | 
				
			||||||
 | 
					        int Delete(TKey id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if net40
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					        Task<TEntity> GetAsync(TKey id);
 | 
				
			||||||
 | 
					        Task<TEntity> FindAsync(TKey id);
 | 
				
			||||||
 | 
					        Task<int> DeleteAsync(TKey id);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,74 +0,0 @@
 | 
				
			|||||||
using System.Collections.Generic;
 | 
					 | 
				
			||||||
using System.Threading.Tasks;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace FreeSql
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    public interface IBasicRepository<TEntity> : IReadOnlyRepository<TEntity>
 | 
					 | 
				
			||||||
        where TEntity : class
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        TEntity Insert(TEntity entity);
 | 
					 | 
				
			||||||
        List<TEntity> Insert(IEnumerable<TEntity> entitys);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        /// <summary>
 | 
					 | 
				
			||||||
        /// 清空状态数据
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					 | 
				
			||||||
        void FlushState();
 | 
					 | 
				
			||||||
        /// <summary>
 | 
					 | 
				
			||||||
        /// 附加实体,可用于不查询就更新或删除
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					 | 
				
			||||||
        /// <param name="entity"></param>
 | 
					 | 
				
			||||||
        void Attach(TEntity entity);
 | 
					 | 
				
			||||||
        void Attach(IEnumerable<TEntity> entity);
 | 
					 | 
				
			||||||
        /// <summary>
 | 
					 | 
				
			||||||
        /// 附加实体,并且只附加主键值,可用于不更新属性值为null或默认值的字段
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					 | 
				
			||||||
        /// <param name="data"></param>
 | 
					 | 
				
			||||||
        IBasicRepository<TEntity> AttachOnlyPrimary(TEntity data);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int Update(TEntity entity);
 | 
					 | 
				
			||||||
        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; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int Delete(TEntity entity);
 | 
					 | 
				
			||||||
        int Delete(IEnumerable<TEntity> entitys);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if net40
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
        Task<TEntity> InsertAsync(TEntity entity);
 | 
					 | 
				
			||||||
        Task<List<TEntity>> InsertAsync(IEnumerable<TEntity> entitys);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Task<int> UpdateAsync(TEntity entity);
 | 
					 | 
				
			||||||
        Task<int> UpdateAsync(IEnumerable<TEntity> entitys);
 | 
					 | 
				
			||||||
        Task<TEntity> InsertOrUpdateAsync(TEntity entity);
 | 
					 | 
				
			||||||
        Task SaveManyAsync(TEntity entity, string propertyName);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Task<int> DeleteAsync(TEntity entity);
 | 
					 | 
				
			||||||
        Task<int> DeleteAsync(IEnumerable<TEntity> entitys);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public interface IBasicRepository<TEntity, TKey> : IBasicRepository<TEntity>, IReadOnlyRepository<TEntity, TKey>
 | 
					 | 
				
			||||||
        where TEntity : class
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        int Delete(TKey id);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if net40
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
        Task<int> DeleteAsync(TKey id);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@@ -1,31 +0,0 @@
 | 
				
			|||||||
using System;
 | 
					 | 
				
			||||||
using System.Linq.Expressions;
 | 
					 | 
				
			||||||
using System.Threading.Tasks;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace FreeSql
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    public interface IReadOnlyRepository<TEntity> : IBaseRepository
 | 
					 | 
				
			||||||
        where TEntity : class
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        IDataFilter<TEntity> DataFilter { get; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        ISelect<TEntity> Select { get; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        ISelect<TEntity> Where(Expression<Func<TEntity, bool>> exp);
 | 
					 | 
				
			||||||
        ISelect<TEntity> WhereIf(bool condition, Expression<Func<TEntity, bool>> exp);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public interface IReadOnlyRepository<TEntity, TKey> : IReadOnlyRepository<TEntity>
 | 
					 | 
				
			||||||
        where TEntity : class
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        TEntity Get(TKey id);
 | 
					 | 
				
			||||||
        TEntity Find(TKey id);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if net40
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
        Task<TEntity> GetAsync(TKey id);
 | 
					 | 
				
			||||||
        Task<TEntity> FindAsync(TKey id);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user