You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There seems to be an issue with SelectMany when called from VB. The same queries work in C#. I've created an example using the Blogging database from here. I've added a property Posts to the Blog object, which returns a collection of the posts associated with a blog
I've attached a zipped solution that contains the VB project along with a file CreateDatabase.sql which will create the database and add a blog and two posts. The solution also contains a C# project that references the model defined in the VB project and executes the same query that fails in VB
System.InvalidOperationException
HResult=0x80131509
Message=The LINQ expression 'x => (IEnumerable<Post>)x.Posts' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Source=Microsoft.EntityFrameworkCore
StackTrace:
at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.ProcessSelectMany(NavigationExpansionExpression source, LambdaExpression collectionSelector, LambdaExpression resultSelector)
at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.Expand(Expression query)
at Microsoft.EntityFrameworkCore.Query.QueryTranslationPreprocessor.Process(Expression query)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
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.EntityQueryable`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at EFBug.Program.Main(String[] args) in C:\Temp\Saturn\EFBug\Program.vb:line 6
EF Core version: 6.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Windows 10
IDE: Visual Studio 202 17.3.4
The text was updated successfully, but these errors were encountered:
i.e., pretty much any where clause. I suspect there would be other ways to achieve the same thing
smitpatel
changed the title
Calling SelectMay from VB throws InvalidOperationException
Calling SelectMany from VB throws InvalidOperationException
Sep 26, 2022
EFBug.zip
File a bug
There seems to be an issue with SelectMany when called from VB. The same queries work in C#. I've created an example using the Blogging database from here. I've added a property Posts to the Blog object, which returns a collection of the posts associated with a blog
I've attached a zipped solution that contains the VB project along with a file CreateDatabase.sql which will create the database and add a blog and two posts. The solution also contains a C# project that references the model defined in the VB project and executes the same query that fails in VB
The following query gives an error in VB:
The same query works in C#:
Other variants on the query fail in the same way, for example:
The exception details are as follows
EF Core version: 6.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Windows 10
IDE: Visual Studio 202 17.3.4
The text was updated successfully, but these errors were encountered: