diff --git a/Src/Asp.Net/SqlServerTest/Demo/Demo2_Queryable.cs b/Src/Asp.Net/SqlServerTest/Demo/Demo2_Queryable.cs index 288f6defb..81d91b8d3 100644 --- a/Src/Asp.Net/SqlServerTest/Demo/Demo2_Queryable.cs +++ b/Src/Asp.Net/SqlServerTest/Demo/Demo2_Queryable.cs @@ -5,7 +5,12 @@ using System.Text; namespace OrmTest.Demo { - class Demo2_Queryable + public class Demo2_Queryable { + + public static void Init() + { + + } } } diff --git a/Src/Asp.Net/SqlServerTest/Demo/Democ_GobalFilter.cs b/Src/Asp.Net/SqlServerTest/Demo/Democ_GobalFilter.cs new file mode 100644 index 000000000..2d5fbf40d --- /dev/null +++ b/Src/Asp.Net/SqlServerTest/Demo/Democ_GobalFilter.cs @@ -0,0 +1,74 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OrmTest +{ + public class Democ_GobalFilter + { + public static void Init() + { + var db = GetInstance(); + + + var sql = db.Queryable().ToSql(); + //SELECT [Id],[Name],[Price],[CreateTime] FROM [Order] WHERE isDelete=0 + Console.WriteLine(sql); + + + var sql2 = db.Queryable((main,ot)=> main.Id==ot.OrderId).ToSql(); + //SELECT [Id],[Name],[Price],[CreateTime] FROM [Order] main ,[OrderDetail] ot WHERE ( [main].[Id] = [ot].[OrderId] ) AND main.isDelete=0 + Console.WriteLine(sql2); + + + var sql3 = db.Queryable().Filter("Myfilter").ToSql();// Myfilter+Gobal + //SELECT [Id],[Name],[Price],[CreateTime] FROM [Order] WHERE Name='jack' AND isDelete=0 + Console.WriteLine(sql3); + + var sql4 = db.Queryable().Filter("Myfilter",isDisabledGobalFilter:true).ToSql();//only Myfilter + //SELECT [Id],[Name],[Price],[CreateTime] FROM [Order] WHERE Name='jack' + Console.WriteLine(sql4); + } + + + public static SqlSugarClient GetInstance() + { + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.SqlServer, ConnectionString = Config.ConnectionString, IsAutoCloseConnection = true }); + + //single table query gobal filter + db.QueryFilter.Add(new SqlFilterItem() + { + FilterValue = filterDb => + { + //Writable logic + return new SqlFilterResult() { Sql = " isDelete=0" };//Global string perform best + } + }); + + //Multi-table query gobal filter + db.QueryFilter.Add(new SqlFilterItem() + { + FilterValue = filterDb => + { + //Writable logic + return new SqlFilterResult() { Sql = " main.isDelete=0" }; + }, + IsJoinQuery=true + }); + + //Specific filters + db.QueryFilter.Add(new SqlFilterItem() + { + FilterName= "Myfilter", + FilterValue = filterDb => + { + //Writable logic + return new SqlFilterResult() { Sql = "Name='jack'" }; + } + }); + return db; + } + } +} diff --git a/Src/Asp.Net/SqlServerTest/Program.cs b/Src/Asp.Net/SqlServerTest/Program.cs index 31943712d..951f5e7c7 100644 --- a/Src/Asp.Net/SqlServerTest/Program.cs +++ b/Src/Asp.Net/SqlServerTest/Program.cs @@ -8,9 +8,10 @@ namespace OrmTest { static void Main(string[] args) { - OldTestMain.Init(); + //OldTestMain.Init(); Demo1_SqlSugarClient.Init(); + Democ_GobalFilter.Init(); Console.WriteLine("all successfully."); Console.ReadKey(); diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj index 44d9db191..bee20726e 100644 --- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj +++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj @@ -49,6 +49,7 @@ +