Browse Source

-

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
108e9a03c2
  1. 36
      SqlServerTest/Demos/Filter.cs
  2. 8
      SqlSugar/Abstract/FilterProvider/FilterProvider.cs
  3. 8
      SqlSugar/Entities/SqlFilter.cs
  4. 14
      SqlSugar/Interface/IFilter.cs
  5. 1
      SqlSugar/SqlSugar.csproj

36
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<Student>().ToSql();
var sql2 = db.Queryable<Student, School>((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<SugarParameter>() { } };
},
IsJoinQuery = false
}).Add(new SqlFilterItem()
{
FilterValue = filterDb =>
{
return new SqlFilterResult() { Sql = " f.isDelete=0", Parameters = new List<SugarParameter>() { } };
},
IsJoinQuery = true
});
return db;
}
}
}

8
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<SqlFilterItem> _Filters { get; set; }
public void Add(SqlFilterItem filter)
public IFilter Add(SqlFilterItem filter)
{
if (_Filters == null)
_Filters = new List<SqlFilterItem>();
_Filters.Add(filter);
return this;
}
public void Remove(string filterName)

8
SqlSugar/Entities/SqlFilter.cs

@ -7,8 +7,14 @@ namespace SqlSugar
{
public class SqlFilterItem
{
/// <summary>
/// Equal to NULL representing global
/// </summary>
public string FilterName { get; set; }
public Func<SqlSugarClient,SqlFilterResult> GetFilterSql { get; set; }
public Func<SqlSugarClient,SqlFilterResult> FilterValue { get; set; }
/// <summary>
/// Is it a multiple table query?
/// </summary>
public bool IsJoinQuery { get; set; }
}

14
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<SqlFilterItem> GeFilterList { get; }
}
}

1
SqlSugar/SqlSugar.csproj

@ -72,6 +72,7 @@
<Compile Include="Interface\ICacheManager.cs" />
<Compile Include="Entities\SugarMessageResult.cs" />
<Compile Include="Enum\InitKeyType.cs" />
<Compile Include="Interface\IFilter.cs" />
<Compile Include="Realization\MySql\DbType.cs" />
<Compile Include="Realization\MySql\DbBind\MySqlDbBind.cs" />
<Compile Include="Realization\MySql\SqlBuilder\MySqlBuilder.cs" />

Loading…
Cancel
Save