Browse Source

Update Demo

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
14d556fe5c
  1. 7
      Src/Asp.Net/SqlServerTest/Demo/Demo2_Queryable.cs
  2. 74
      Src/Asp.Net/SqlServerTest/Demo/Democ_GobalFilter.cs
  3. 3
      Src/Asp.Net/SqlServerTest/Program.cs
  4. 1
      Src/Asp.Net/SqlServerTest/SqlServerTest.csproj

7
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()
{
}
}
}

74
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<Order>().ToSql();
//SELECT [Id],[Name],[Price],[CreateTime] FROM [Order] WHERE isDelete=0
Console.WriteLine(sql);
var sql2 = db.Queryable<Order,OrderItem>((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<Order>().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<Order>().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;
}
}
}

3
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();

1
Src/Asp.Net/SqlServerTest/SqlServerTest.csproj

@ -49,6 +49,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Demo\Democ_GobalFilter.cs" />
<Compile Include="Demo\Demo2_Queryable.cs" />
<Compile Include="Models\MyCustomAttributeTable.cs" />
<Compile Include="Models\Order.cs" />

Loading…
Cancel
Save