![](/img/trans.png)
[英]Entity Framework Core 3.0 - Lambda expression used inside Include is not valid
[英]Lambda expression used inside Include is not valid in Entity Framework Core
我想在 EntityFramework Core 3.1 中進行查詢
這是我的查詢:
return await context_client.Tbcategoriapregunta.Include(e => e.Tbpreguntasfrecuentes.Where(preguntas => preguntas.Dstipousuario == user)).ToListAsync();
但不起作用,這是消息錯誤
Lambda expression used inside Include is not valid.
這是消息 StackTrace
at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.ProcessInclude(NavigationExpansionExpression source, Expression expression, Boolean thenInclude) at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor訪問者)在 System.Linq.Expressions.ExpressionVisitor.Visit(表達式節點)在 Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.Expand(表達式查詢)在 Microsoft.EntityFrameworkCore.Query.QueryTranslationPreprocessor.Process(表達式查詢)在 Microsoft.EntityFrameworkCore .Query.QueryCompilationContext.CreateQueryExecutor[TResult](表達式查詢)在 Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](表達式查詢,Z27226C864BAC7454A8504F8EDB15D95B Z 異步)在 Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase 數據庫,表達式查詢,IModel model,Boolean 異步)在 Microsoft.EntityFrameworkCore<c__DisplayClass1>ExecAsync.<c__DisplayClass1
1.<ExecuteAsync>b__0() at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func
1 編譯器) 在 Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable
微軟1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable
.EntityQueryable 1.GetAsyncEnumerator(CancellationToken cancelToken) .EntityFrameworkCore.EntityFrameworkQueryableExtensions.IncludableQueryable2.GetAsyncEnumerator(CancellationToken cancellationToken) at System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable
1.GetAsyncEnumerator() 在 Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.d__641.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() 在 Business.Implementation.BsCategoriaPregunta.d__4 .MoveNext() 在 C:\Users\admin\source\repos\API013-Ayuda\Business\Implementation\BsCategoriaPregunta.cs:line 58
任何想法...???
Include()
的目的是告訴它在處理此查詢的同時從相關表中加載數據。
文檔中的示例使用了一個場景,您希望從數據庫中加載博客列表,並且還包括與每個博客相關的帖子:
using (var context = new BloggingContext())
{
var blogs = context.Blogs
.Include(blog => blog.Posts)
.ToList();
}
所以在Include()
Where()
是沒有意義的。
您必須告訴我們您要做什么。 但也許這樣的事情可能會奏效?
return await context_client.Tbcategoriapregunta
.Include(e => e.Tbpreguntasfrecuentes)
.Where(categoria => categoria.Tbpreguntasfrecuentes.Dstipousuario == user)
.ToListAsync();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.