mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
add ExpressionCall tests #269
This commit is contained in:
parent
4e4240ff7a
commit
d97dc3383c
@ -121,6 +121,13 @@
|
||||
清空状态数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.DbSet`1.RemoveAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
|
||||
<summary>
|
||||
根据 lambda 条件删除数据
|
||||
</summary>
|
||||
<param name="predicate"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.DbSet`1.Add(`0)">
|
||||
<summary>
|
||||
添加
|
||||
@ -215,6 +222,15 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:FreeSql.IBaseRepository.Orm">
|
||||
<summary>
|
||||
注意:IFreeSql 属于顶级对象,事务无法自动传递。<para></para>
|
||||
|
67
FreeSql.Tests/FreeSql.Tests/Issues/269.cs
Normal file
67
FreeSql.Tests/FreeSql.Tests/Issues/269.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using FreeSql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NpgsqlTypes;
|
||||
using Npgsql.LegacyPostgis;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Threading;
|
||||
using System.Data.SqlClient;
|
||||
using kwlib;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace FreeSql.Tests.Issues
|
||||
{
|
||||
public class _269
|
||||
{
|
||||
[Fact]
|
||||
public void ToSql()
|
||||
{
|
||||
var fsql = g.sqlite;
|
||||
|
||||
var sql1 = fsql.Select<Edi>()
|
||||
.Where(a =>
|
||||
DbFunc222.FuncExpression<EDIUseMode?, EDIUseMode, EDIUseMode>("ISNULL", a.UseMode, EDIUseMode.Both) == EDIUseMode.Both)
|
||||
.ToSql(); //这么写报错:ExpressionTree 转换类型错误,值(a.[EDI_USE_MODE]),类型(System.String),目标类型(System.Nullable`1[EDIUseMode]),Requested value 'a.[EDI_USE_MODE]' was not found.
|
||||
var sql2 = fsql.Select<Edi>()
|
||||
.Where(a =>
|
||||
DbFunc222.FuncExpression<int?, int, int>("ISNULL", (int)a.UseMode, (int)EDIUseMode.Both) == (int)EDIUseMode.Both)
|
||||
.ToSql(); //这么写就不报错
|
||||
|
||||
}
|
||||
|
||||
public enum EDIUseMode : byte
|
||||
{
|
||||
OutPut = 1,
|
||||
Import = 2,
|
||||
Both = 3,
|
||||
}
|
||||
[Table(Name = "EDI222")]
|
||||
public class Edi
|
||||
{
|
||||
[Column(Name = "EDI_ID")] public long Id { get; set; }
|
||||
[Column(Name = "EDI_USE_MODE")] public EDIUseMode? UseMode { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
[ExpressionCall]
|
||||
public static class DbFunc222
|
||||
{
|
||||
static ThreadLocal<ExpressionCallContext> context = new ThreadLocal<ExpressionCallContext>();
|
||||
//自定义数据库方法
|
||||
public static TOut FuncExpression<T1, T2, TOut>(string func, T1 p1, T2 p2)
|
||||
{
|
||||
var up = context.Value;
|
||||
var values = up.ParsedContent.Values.ToArray();
|
||||
context.Value.Result = $"{func}({values[1]}, {values[2]})";
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
7377
FreeSql/FreeSql.xml
7377
FreeSql/FreeSql.xml
File diff suppressed because it is too large
Load Diff
@ -646,11 +646,13 @@ namespace FreeSql.Internal
|
||||
var eccContent = ecc.ParsedContent[exp3MethodParams[a].Name];
|
||||
if (eccContent == null)
|
||||
exp3InvokeParams[a] = Expression.Lambda(exp3.Arguments[a]).Compile().DynamicInvoke();
|
||||
else if (exp3.Arguments[a].IsParameter())
|
||||
exp3InvokeParams[a] = exp3.Arguments[a].Type.CreateInstanceGetDefaultValue();
|
||||
else
|
||||
exp3InvokeParams[a] = Utils.GetDataReaderValue(exp3.Arguments[a].Type,
|
||||
eccContent.StartsWith("N'") ?
|
||||
eccContent.Substring(1).Trim('\'').Replace("''", "'") :
|
||||
eccContent.Trim('\'').Replace("''", "'"));// exp3.Arguments[a].Type.CreateInstanceGetDefaultValue();
|
||||
eccContent.Trim('\'').Replace("''", "'"));
|
||||
}
|
||||
else
|
||||
exp3InvokeParams[a] = ecc;
|
||||
|
Loading…
x
Reference in New Issue
Block a user