扩展函数参数丢失TypeName 返回
public class DemoSqlFunction
{
public static bool MyContainsArrayUseSqlParameters<T>(List<T> thisValue, object InField)
{
//这里不能写任何实现代码,需要在上面的配置中实现
throw new NotSupportedException("Can only be used in expressions");
}
private static List<SqlFuncExternal> _SqlFuncExternals;
public static List<SqlFuncExternal> SqlFuncExternals()
{
if (_SqlFuncExternals != null)
{
return _SqlFuncExternals;
}
var expMethods = new List<SqlFuncExternal>
{
new SqlFuncExternal()
{
UniqueMethodName = "MyContainsArrayUseSqlParameters",
MethodValue = (expInfo, dbType, expContext) =>
{
if (dbType == SugarDbType.SqlServer)
{
var inValueIEnumerable = (IEnumerable)expInfo.Args[0].MemberValue;
var tempDt = new DataTable();
tempDt.Columns.Add("Value", typeof(long));
foreach (var item in inValueIEnumerable)
{
var r = tempDt.NewRow();
r["Value"] = item;
tempDt.Rows.Add(r);
}
var tempTable = $"@tempArrayTable{Guid.NewGuid().ToString().Replace("-", "")}";
//表结构变量
expContext.Parameters.Add(new SugarParameter(tempTable, tempDt, "dbo.Long_Table"));
return $"{expInfo.Args[1].MemberName} IN (SELECT Value FROM {tempTable})";
}
else
throw new Exception("未实现");
}
}
};
return expMethods;
}
}
源码版本:
热忱回答(3)
-
VIP02023/12/1
代码会将对象重新赋值并丢失内部对象
0 回复 -
VIP02023/12/1
@ :这个是gittree最新版本5.1.4.124
0 回复 -
fate sta VIP02023/12/1
SqlSugarCore 5.1.4.125-preview15
勾一下预览已处理 ,过五分钟后
0 回复