mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 20:13:41 +08:00
-
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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)
|
||||
|
@@ -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
Normal file
14
SqlSugar/Interface/IFilter.cs
Normal file
@@ -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; }
|
||||
}
|
||||
}
|
@@ -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" />
|
||||
|
Reference in New Issue
Block a user