Skip to content

Commit

Permalink
v3.2.806-preview20231204 - 增加 WithSql().WhereDynamicFilter 的支持;
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Dec 3, 2023
1 parent 60d3292 commit 2bfb9c2
Show file tree
Hide file tree
Showing 35 changed files with 73 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!--
经常出于版本交叉问题,暂时关闭,在每个项目上设置版本号
<PropertyGroup>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
</PropertyGroup>
-->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<LangVersion>latest</LangVersion>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Title>$(AssemblyName)</Title>
<IsPackable>true</IsPackable>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Extensions/FreeSql.Generator/FreeSql.Generator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
<RepositoryUrl>https://github.com/2881099/FreeSql</RepositoryUrl>
<PackageTags>FreeSql DbFirst 实体生成器</PackageTags>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion FreeSql.All/FreeSql.All.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion FreeSql.DbContext/FreeSql.DbContext.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
18 changes: 0 additions & 18 deletions FreeSql.DbContext/FreeSql.DbContext.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion FreeSql.Repository/FreeSql.Repository.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
17 changes: 11 additions & 6 deletions FreeSql/Extensions/FreeSqlGlobalExpressionCallExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,18 @@ static bool InternalRawSql([RawValue] string sql)
expContext.Value.Result = sql;
return false;
}
static object InternalRawField([RawValue] string sql)
{
expContext.Value.Result = sql;
return default;
}

#region 大小判断
/// <summary>
/// 大于 &gt;
/// </summary>
/// <returns></returns>
public static bool GreaterThan<TValue>(TValue value1, TValue value2)
#region 大小判断
/// <summary>
/// 大于 &gt;
/// </summary>
/// <returns></returns>
public static bool GreaterThan<TValue>(TValue value1, TValue value2)
{
expContext.Value.Result = $"{expContext.Value.ParsedContent["value1"]} > {expContext.Value.ParsedContent["value2"]}";
return false;
Expand Down
2 changes: 1 addition & 1 deletion FreeSql/FreeSql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
27 changes: 24 additions & 3 deletions FreeSql/Internal/CommonProvider/SelectProvider/Select0Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,26 @@ public SelectTableInfo GetOutsideSelectTable(ParameterExpression parameterExp)
}
}

public Expression ConvertStringPropertyToExpression(string property, bool fromFirstTable = false)
public static MethodInfo _methodSqlExtInternalRawField = typeof(SqlExt).GetMethod("InternalRawField", BindingFlags.NonPublic | BindingFlags.Static);
public static MethodInfo _methodSqlExtInternalRawSql = typeof(SqlExt).GetMethod("InternalRawSql", BindingFlags.NonPublic | BindingFlags.Static);
public Expression ConvertStringPropertyToExpression(string property, bool fromFirstTable = false)
{
if (string.IsNullOrEmpty(property)) return null;
var field = property.Split('.').Select(a => a.Trim()).ToArray();
Expression exp = null;

if (field.Length == 1 && fromFirstTable == false)
{
foreach (var tb in _tables)
if (_tables.Count == 1 && _tables[0].Table?.Type == typeof(object))
{
//配合 .Select<object>().WithSql("...").WhereDynamicFilter(...)
var tb = _tables[0];
tb.Parameter = Expression.Parameter(tb.Table.Type, tb.Alias);
var rawField = $"{tb.Alias}.{_commonUtils.QuoteSqlName(field[0])}";
return Expression.Call(_methodSqlExtInternalRawField, Expression.Constant(rawField, typeof(string)));
}

foreach (var tb in _tables)
{
if (tb.Table.ColumnsByCs.TryGetValue(field[0], out var col) &&
tb.Table.Properties.TryGetValue(field[0], out var prop))
Expand Down Expand Up @@ -1029,7 +1040,7 @@ void ParseFilter(DynamicFilterLogic logic, DynamicFilterInfo fi, bool isend)
.Select(a => a.ParameterType == typeof(object) ? (object)this :
(a.ParameterType == typeof(string) ? (object)(fi.Value?.ToString()) : (object)null))
.ToArray());
exp = fiValue0MethodReturn is Expression expression ? expression : Expression.Call(typeof(SqlExt).GetMethod("InternalRawSql", BindingFlags.NonPublic | BindingFlags.Static), Expression.Constant(fiValue0MethodReturn?.ToString(), typeof(string)));
exp = fiValue0MethodReturn is Expression expression ? expression : Expression.Call(_methodSqlExtInternalRawSql, Expression.Constant(fiValue0MethodReturn?.ToString(), typeof(string)));
break;

case DynamicFilterOperator.Contains:
Expand All @@ -1043,6 +1054,16 @@ void ParseFilter(DynamicFilterLogic logic, DynamicFilterInfo fi, bool isend)
break;
default:
exp = ConvertStringPropertyToExpression(fi.Field);
if (exp.Type == typeof(object) && fi.Value != null)
{
var valueType = fi.Value?.GetType();
if (Utils.dicExecuteArrayRowReadClassOrTuple.ContainsKey(valueType)) exp = Expression.Convert(exp, valueType);
else if (valueType.FullName == "System.Text.Json.JsonElement")
{
var valueKind = valueType.GetProperty("ValueKind").GetValue(fi.Value, null).ToString();
if (valueKind == "Number") exp = Expression.Convert(exp, typeof(decimal));
}
}
break;
}
switch (fi.Operator)
Expand Down
7 changes: 7 additions & 0 deletions FreeSql/Internal/UtilsExpressionTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ internal static TableInfo GetTableByEntity(Type entity, CommonUtils common)
) return null;
var tbc = _cacheGetTableByEntity.GetOrAdd(common._orm.Ado.DataType, k1 => new ConcurrentDictionary<Type, TableInfo>()); //区分数据库类型缓存
if (tbc.TryGetValue(entity, out var trytb)) return trytb;
if (entity == typeof(object)) return new TableInfo
{
Type = entity,
CsName = entity.Name,
DbName = entity.Name,
DisableSyncStructure = true,
};
if (common.CodeFirst.GetDbInfo(entity) != null) return null;
if (typeof(IEnumerable).IsAssignableFrom(entity) && entity.IsGenericType == true) return null;
if (entity.IsArray) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<SignAssembly>False</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Title>$(AssemblyName)</Title>
<IsPackable>true</IsPackable>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Title>$(AssemblyName)</Title>
<IsPackable>true</IsPackable>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Title>$(AssemblyName)</Title>
<IsPackable>true</IsPackable>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<Version>3.2.806-preview20231201</Version>
<Version>3.2.806-preview20231204</Version>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Loading

0 comments on commit 2bfb9c2

Please sign in to comment.