向 <Class> 类型的字符串插入查询时出错

问题描述 投票:0回答:0

我最近一直在尝试将查询结果(即 DailyPerformances 列表)插入到列表中,以获取哪些信息为空并获取其列名。它就像一个过滤器,可以知道哪些列名发送,哪些不发送。问题是,当我执行代码时,它给我一个错误:

System.NotSupportedException:无法解析表达式“<>h__TransparentIdentifier0.DailyPerformance”,因为它具有不受支持的类型。只能解析查询源(即实现 IEnumerable 的表达式)和查询运算符。 ---> System.ArgumentException:参数“expression.Type”是“KNUTSEN_OAS.Models.DaiylePerformance”,不能分配给类型“System.Collections.IEnumerable”。 参数名称:expression.Type

at Remotion.Utilities.ArgumentUtility.CheckTypeIsAssignableFrom(String argumentName, Type actualType, Type expectedType)
at Remotion.Linq.Parsing.Structure.IntermediateModel.MainSourceExpressionNode..ctor(String associatedIdentifier, Expression expression)
at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseNonQueryOperatorExpression(Expression expression, String associatedIdentifier)
\--- End of inner exception stack trace ---
at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseNonQueryOperatorExpression(Expression expression, String associatedIdentifier)
at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseNode(Expression expression, String associatedIdentifier)
at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseMethodCallExpression(MethodCallExpression methodCallExpression, String associatedIdentifier)
at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseNode(Expression expression, String associatedIdentifier)
at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseMethodCallExpression(MethodCallExpression methodCallExpression, String associatedIdentifier)
at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseNode(Expression expression, String associatedIdentifier)
at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseMethodCallExpression(MethodCallExpression methodCallExpression, String associatedIdentifier)
at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseTree(Expression expressionTree)
at Remotion.Linq.Parsing.Structure.QueryParser.GetParsedQuery(Expression expressionTreeRoot)
at Remotion.Linq.Parsing.ExpressionVisitors.SubQueryFindingExpressionVisitor.Visit(Expression expression)
at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)
at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Remotion.Linq.Parsing.ExpressionVisitors.SubQueryFindingExpressionVisitor.Visit(Expression expression)
at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Remotion.Linq.Parsing.ExpressionVisitors.SubQueryFindingExpressionVisitor.Visit(Expression expression)
at System.Linq.Expressions.ExpressionVisitor.VisitLambda\[T\](Expression`1 node)    at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Remotion.Linq.Parsing.ExpressionVisitors.SubQueryFindingExpressionVisitor.Visit(Expression expression)
at Remotion.Linq.Parsing.ExpressionVisitors.SubQueryFindingExpressionVisitor.Process(Expression expressionTree, INodeTypeProvider nodeTypeProvider)
at Remotion.Linq.Parsing.Structure.MethodCallExpressionParser.ProcessArgumentExpression(Expression argumentExpression)
at System.Linq.Enumerable.SelectListPartitionIterator`2.ToArray()    at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Remotion.Linq.Parsing.Structure.MethodCallExpressionParser.Parse(String associatedIdentifier, IExpressionNode source, IEnumerable`1 arguments, MethodCallExpression expressionToParse)    at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseMethodCallExpression(MethodCallExpression methodCallExpression, String associatedIdentifier)    at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseNode(Expression expression, String associatedIdentifier)    at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseMethodCallExpression(MethodCallExpression methodCallExpression, String associatedIdentifier)    at Remotion.Linq.Parsing.Structure.ExpressionTreeParser.ParseTree(Expression expressionTree)    at Remotion.Linq.Parsing.Structure.QueryParser.GetParsedQuery(Expression expressionTreeRoot)    at Microsoft.EntityFrameworkCore.Query.Internal.QueryModelGenerator.ParseQuery(Expression query)    at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, IQueryModelGenerator queryModelGenerator, IDatabase database, IDiagnosticsLogger`1 logger, Type contextType)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.\<\>c__DisplayClass13_0`1.<Execute>b__0()    at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery\[TResult\](Object cacheKey, Func`1 compiler)    at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)    at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)    at Remotion.Linq.QueryableBase`1.GetEnumerator()
at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at System.Linq.Enumerable.ConcatIterator`1.ToList()    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at KNUTSEN_OAS.Controllers.SummaryController.SelectedVessels(Int32\[\] vector) in D:\\Proyectos\\Knutsen\\trunk\\KNUTSEN OAS\\Controllers\\SummaryController.cs:line 713

出题方法是这样的:

[HttpPost]
public IActionResult SelectedVessels([FromBody]int[] vector)
{
    try
    {
        if (vector == null)
            return Json(new { error = "Data is null" });
        else
        {
            List<DaiylePerformance> daiylePerformance = new List<DaiylePerformance>();

            foreach (var v in vector.Distinct())
            {
                daiylePerformance.Concat(
                    from DailyPerformance in _context.daiylePerformances
                    join Voyage in _context.VoyageProperties on   DailyPerformance.VoyageId equals Voyage.Id
                    where Voyage.Id.Equals(v) &&
                        !DailyPerformance.GetType().GetProperties().Any(x => x.GetValue(DailyPerformance) == null)
                    select new DaiylePerformance(_context)
                    ).ToList();
            }

            _logger.LogError("\nConsulta pasada\n");

            List<string> columNames = typeof(DaiylePerformance).GetProperties().Select(d => d.Name).Distinct().ToList();
            _logger.LogError("\nLista de nombres pasada\n");

            //foreach (var i in DailyPerformance)
            //{
            //    Debug.WriteLine("Esto es un elemento " + i);
            //}
            return Json(new { success = true, data = columNames });
        }
    }
    catch(Exception ex)
    {
        _logger.LogError(ex, "Error in SelectedVessels method con excepcion: " + ex);

        return Json(new { error = "An error ocurred while processing the request" });
    }
}

接收到的向量是从视图中接收到的血管编号向量。 通过我所做的所有测试,我认为这就是查询。 提前致谢。 :)

c# linq iqueryable
© www.soinside.com 2019 - 2024. All rights reserved.