PgsqlArrayContains 方法报错 返回
ConnectionConfig config = new()
{
DbType = SqlSugar.DbType.PostgreSQL,
ConnectionString = "",
IsAutoCloseConnection = true};SqlSugarScope sqlSugar = new SqlSugarScope(config, db =>
{
});
var tempIds = sqlSugar.Queryable<User>()
.InnerJoin<Role>((u, ur) => SqlFunc.PgsqlArrayContains(u.RoleIds, 1))
.Select(u => u.Id)
.Distinct()
.ToList();
var tempIds2 = sqlSugar.Queryable<User>()
.InnerJoin<Role>((u, ur) => SqlFunc.PgsqlArrayContains(u.RoleIds, ur.Id))
.Select(u => u.Id)
.Distinct()
.ToList();
Console.ReadLine();
public class Role{
public long Id { get; set; }
}
public class User{
public long Id { get; set; }
public long[] RoleIds { get; set; } = Array.Empty<long>();
}如上述代码, 使用固定参数
SqlFunc.PgsqlArrayContains(u.RoleIds, 1)
时 没有问题。 但是使用列关联会报错
System.Reflection.TargetInvocationException
HResult=0x80131604
Message=Exception has been thrown by the target of an invocation.
Source=System.Private.CoreLib
StackTrace:
在 System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
在 System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
在 SqlSugar.MethodCallExpressionResolve.GetMethodValue(String name, MethodCallExpressionModel model)
在 SqlSugar.MethodCallExpressionResolve.Where(ExpressionParameter parameter, Nullable`1 isLeft, String name, IEnumerable`1 args, MethodCallExpressionModel model, List`1 appendArgs)
在 SqlSugar.MethodCallExpressionResolve.SqlFuncMethod(ExpressionParameter parameter, MethodCallExpression express, Nullable`1 isLeft)
在 SqlSugar.MethodCallExpressionResolve..ctor(ExpressionParameter parameter)
在 SqlSugar.BaseResolve.Start()
在 SqlSugar.LambdaExpressionResolve..ctor(ExpressionParameter parameter)
在 SqlSugar.BaseResolve.Start()
在 SqlSugar.ExpressionContext.Resolve(Expression expression, ResolveExpressType resolveType)
在 SqlSugar.QueryBuilder.GetExpressionValue(Expression expression, ResolveExpressType resolveType)
在 SqlSugar.QueryableProvider`1.GetJoinInfo(Expression joinExpression, JoinType joinType)
在 SqlSugar.QueryableProvider`1.InnerJoin[T2](Expression`1 joinExpression)
在 Program.<Main>$(String[] args) 在 C:\TestCode\TestSqlSugar\TestSqlSugar\Program.cs 中: 第 23 行
热忱回答(2)
-
fate sta VIP0
1周前实体没加isarray=true
0 回复 -
VIP0
1周前using Newtonsoft.Json; using SqlSugar;using System.Data; using TestSqlSugar; ConnectionConfig config = new() { DbType = SqlSugar.DbType.PostgreSQL, ConnectionString = "", IsAutoCloseConnection = true};SqlSugarScope sqlSugar = new SqlSugarScope(config, db => { }); sqlSugar.CodeFirst.InitTables(typeof(User)); sqlSugar.CodeFirst.InitTables(typeof(Role)); var tempIds = sqlSugar.Queryable<User>() .InnerJoin<Role>((u, ur) => SqlFunc.PgsqlArrayContains(u.RoleIds, 1)) .Select(u => u.Id) .Distinct() .ToList(); var tempIds2 = sqlSugar.Queryable<User>() .InnerJoin<Role>((u, ur) => SqlFunc.PgsqlArrayContains(u.RoleIds, ur.Id)) .Select(u => u.Id) .Distinct() .ToList();Console.ReadLine(); [SugarTable("test_role")] public class Role{ public long Id { get; set; } } [SugarTable("test_user")] public class User{ public long Id { get; set; } [SugarColumn(ColumnDataType = "bigint []", IsArray = true)] public long[] RoleIds { get; set; } }加上 ColumnDataType 和 IsArray 是一样的错误
System.Reflection.TargetInvocationException
HResult=0x80131604
Message=Exception has been thrown by the target of an invocation.
Source=System.Private.CoreLib
StackTrace:
在 System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
在 System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
在 SqlSugar.MethodCallExpressionResolve.GetMethodValue(String name, MethodCallExpressionModel model)
在 SqlSugar.MethodCallExpressionResolve.Where(ExpressionParameter parameter, Nullable`1 isLeft, String name, IEnumerable`1 args, MethodCallExpressionModel model, List`1 appendArgs)
在 SqlSugar.MethodCallExpressionResolve.SqlFuncMethod(ExpressionParameter parameter, MethodCallExpression express, Nullable`1 isLeft)
在 SqlSugar.MethodCallExpressionResolve..ctor(ExpressionParameter parameter)
在 SqlSugar.BaseResolve.Start()
在 SqlSugar.LambdaExpressionResolve..ctor(ExpressionParameter parameter)
在 SqlSugar.BaseResolve.Start()
在 SqlSugar.ExpressionContext.Resolve(Expression expression, ResolveExpressType resolveType)
在 SqlSugar.QueryBuilder.GetExpressionValue(Expression expression, ResolveExpressType resolveType)
在 SqlSugar.QueryableProvider`1.GetJoinInfo(Expression joinExpression, JoinType joinType)
在 SqlSugar.QueryableProvider`1.InnerJoin[T2](Expression`1 joinExpression)
在 Program.<Main>$(String[] args) 在 C:\TestCode\TestSqlSugar\TestSqlSugar\Program.cs 中: 第 27 行
此异常最初是在此调用堆栈中引发的:
[外部代码]
内部异常 1:
NullReferenceException: Object reference not set to an instance of an object.
0 回复