mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update Demo
This commit is contained in:
parent
72d17ad240
commit
a6e3868dff
33
Src/Asp.NetCore2/Json2Sql/DynamicLinq.cs
Normal file
33
Src/Asp.NetCore2/Json2Sql/DynamicLinq.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using Npgsql;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Dynamic.Core;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using Test;
|
||||||
|
|
||||||
|
namespace Test
|
||||||
|
{
|
||||||
|
partial class Program
|
||||||
|
{
|
||||||
|
public static void DynamicLinq(ISqlSugarClient db)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
//程序启动时注册
|
||||||
|
StaticConfig.DynamicExpressionParserType = typeof(DynamicExpressionParser);
|
||||||
|
|
||||||
|
db.QueryFilter
|
||||||
|
.AddTableFilter(typeof(Order), "it", $" it.Name={ "jack" } ")
|
||||||
|
.AddTableFilter(typeof(Order), "it", $" it.Id={1} ");
|
||||||
|
db.Queryable<Order>().ToList();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -5,6 +5,10 @@
|
|||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.4" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj" />
|
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -9,23 +9,23 @@ namespace Test
|
|||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
JsonClient jsonToSqlClient = new JsonClient();
|
JsonClient jsonToSqlClient = new JsonClient();
|
||||||
//jsonToSqlClient.Context = new SqlSugarClient(new ConnectionConfig()
|
|
||||||
//{
|
|
||||||
// DbType = DbType.SqlServer,
|
|
||||||
// IsAutoCloseConnection = true,
|
|
||||||
// ConnectionString = "server=.;uid=sa;pwd=sasa;database=SQLSUGAR4XTEST"
|
|
||||||
//});
|
|
||||||
jsonToSqlClient.Context = new SqlSugarClient(new ConnectionConfig()
|
jsonToSqlClient.Context = new SqlSugarClient(new ConnectionConfig()
|
||||||
{
|
{
|
||||||
DbType = DbType.MySql,
|
DbType = DbType.SqlServer,
|
||||||
IsAutoCloseConnection = true,
|
IsAutoCloseConnection = true,
|
||||||
ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=haosql"
|
ConnectionString = "server=.;uid=sa;pwd=sasa;database=SQLSUGAR4XTEST"
|
||||||
}); ;
|
});
|
||||||
TestHelper.InitDatabase(jsonToSqlClient);
|
//jsonToSqlClient.Context = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
//{
|
||||||
|
// DbType = DbType.MySql,
|
||||||
|
// IsAutoCloseConnection = true,
|
||||||
|
// ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=haosql"
|
||||||
|
//}); ;
|
||||||
|
//TestHelper.InitDatabase(jsonToSqlClient);
|
||||||
|
|
||||||
jsonToSqlClient.Context.Aop.OnLogExecuted = (sql, p) =>
|
jsonToSqlClient.Context.Aop.OnLogExecuted = (sql, p) =>
|
||||||
{
|
{
|
||||||
Console.WriteLine(sql);
|
Console.WriteLine(UtilMethods.GetNativeSql(sql,p));
|
||||||
};
|
};
|
||||||
|
|
||||||
Insetable01(jsonToSqlClient);
|
Insetable01(jsonToSqlClient);
|
||||||
@ -44,7 +44,7 @@ namespace Test
|
|||||||
Updateable01(jsonToSqlClient);
|
Updateable01(jsonToSqlClient);
|
||||||
Deleteable01(jsonToSqlClient);
|
Deleteable01(jsonToSqlClient);
|
||||||
|
|
||||||
|
DynamicLinq(jsonToSqlClient.Context);
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user