diff --git a/SqlServerTest/Demos/Filter.cs b/SqlServerTest/Demos/Filter.cs index 5cb306ac2..d0ffb0794 100644 --- a/SqlServerTest/Demos/Filter.cs +++ b/SqlServerTest/Demos/Filter.cs @@ -1,4 +1,5 @@ using OrmTest.Demo; +using OrmTest.Models; using SqlSugar; using System; using System.Collections.Generic; @@ -13,8 +14,39 @@ namespace OrmTest.Demos { public static void Init() { - var db = GetInstance(); - // db.QueryFilter.Add(eSqlFilterItem(){ }); + + + //gobal filter + var db = GetInstance1(); + + var sql = db.Queryable().ToSql(); + + var sql2 = db.Queryable((f, s) => new object[] { JoinType.Left, f.SchoolId == s.Id }).ToSql(); + + //Specify name filter + + } + + public static SqlSugarClient GetInstance1() + { + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true }); + db.QueryFilter + .Add(new SqlFilterItem() + { + FilterValue = filterDb => + { + return new SqlFilterResult() { Sql = " isDelete=0", Parameters = new List() { } }; + }, + IsJoinQuery = false + }).Add(new SqlFilterItem() + { + FilterValue = filterDb => + { + return new SqlFilterResult() { Sql = " f.isDelete=0", Parameters = new List() { } }; + }, + IsJoinQuery = true + }); + return db; } } } diff --git a/SqlSugar/Abstract/FilterProvider/FilterProvider.cs b/SqlSugar/Abstract/FilterProvider/FilterProvider.cs index 57b00ef6d..fef204282 100644 --- a/SqlSugar/Abstract/FilterProvider/FilterProvider.cs +++ b/SqlSugar/Abstract/FilterProvider/FilterProvider.cs @@ -5,15 +5,17 @@ using System.Text; namespace SqlSugar { - public class QueryFilterProvider + public class QueryFilterProvider : IFilter { - internal SqlSugarClient Context{ get; set; } + internal SqlSugarClient Context { get; set; } private List _Filters { get; set; } - public void Add(SqlFilterItem filter) + public IFilter Add(SqlFilterItem filter) { if (_Filters == null) _Filters = new List(); + _Filters.Add(filter); + return this; } public void Remove(string filterName) diff --git a/SqlSugar/Entities/SqlFilter.cs b/SqlSugar/Entities/SqlFilter.cs index 20b45541d..f974c3122 100644 --- a/SqlSugar/Entities/SqlFilter.cs +++ b/SqlSugar/Entities/SqlFilter.cs @@ -7,8 +7,14 @@ namespace SqlSugar { public class SqlFilterItem { + /// + /// Equal to NULL representing global + /// public string FilterName { get; set; } - public Func GetFilterSql { get; set; } + public Func FilterValue { get; set; } + /// + /// Is it a multiple table query? + /// public bool IsJoinQuery { get; set; } } diff --git a/SqlSugar/Interface/IFilter.cs b/SqlSugar/Interface/IFilter.cs new file mode 100644 index 000000000..265a163f5 --- /dev/null +++ b/SqlSugar/Interface/IFilter.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SqlSugar +{ + public interface IFilter + { + IFilter Add(SqlFilterItem filter); + void Remove(string filterName); + List GeFilterList { get; } + } +} diff --git a/SqlSugar/SqlSugar.csproj b/SqlSugar/SqlSugar.csproj index 7ffffe491..d304e4f5f 100644 --- a/SqlSugar/SqlSugar.csproj +++ b/SqlSugar/SqlSugar.csproj @@ -72,6 +72,7 @@ +