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
Filtering on the Primary Key of an Entity, when said Entity contains an OwnedEntity and the query is prefixed with the FromSqlRaw method, will result in an InvalidOperationException.
using Microsoft.EntityFrameworkCore;using System.ComponentModel.DataAnnotations;varcontext=new TestContext();varresult= context.ParentEntities.FromSqlRaw("SELECT * FROM ParentEntities").FirstOrDefault(x => x.Pk ==42);classTestContext:DbContext{publicDbSet<ParentEntity> ParentEntities {get;set;}protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder){
optionsBuilder.UseSqlServer();}}publicclassParentEntity{[Key]publicintPk{get;set;}publicDefaultDefault{get;set;}}[Owned]publicclassDefault{}
stacktrace
System.InvalidOperationException
HResult=0x80131509
Message=Sequence contains no elements
Source=System.Linq
StackTrace:
at System.Linq.ThrowHelper.ThrowNoElementsException()
at System.Linq.Enumerable.Aggregate[TSource](IEnumerable`1 source, Func`3 func)
at Microsoft.EntityFrameworkCore.Query.SqlExpressionFactory.AddConditions(SelectExpression selectExpression, IEntityType entityType)
at Microsoft.EntityFrameworkCore.Query.SqlExpressionFactory.Select(IEntityType entityType, TableExpressionBase tableExpressionBase)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.<>c__DisplayClass9_0.<TryExpand>g__BuildInnerSelectExpressionForOwnedTypeMappedToDifferentTable|1(EntityProjectionExpression entityProjectionExpression, ITableBase targetTable, INavigation navigation)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.TryExpand(Expression source, MemberIdentity member)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.IncludeExpression.VisitChildren(ExpressionVisitor visitor)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.VisitExtension(Expression extensionExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.SharedTypeEntityExpandingExpressionVisitor.Expand(SelectExpression selectExpression, Expression lambdaBody)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.ExpandSharedTypeEntities(SelectExpression selectExpression, Expression lambdaBody)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.RemapLambdaBody(ShapedQueryExpression shapedQueryExpression, LambdaExpression lambdaExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateSelect(ShapedQueryExpression source, LambdaExpression selector)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
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.EntityQueryProvider.Execute[TResult](Expression expression)
at Program.<Main>$(String[] args)
Include provider and version information
EF Core version: 7.0 RC1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 7.0 RC1
Operating system: Windows 10
IDE: Visual Studio 2022 17.4 p1
The text was updated successfully, but these errors were encountered:
Filtering on the Primary Key of an Entity, when said Entity contains an OwnedEntity and the query is prefixed with the
FromSqlRaw
method, will result in anInvalidOperationException
.Code
stacktrace
Include provider and version information
EF Core version: 7.0 RC1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 7.0 RC1
Operating system: Windows 10
IDE: Visual Studio 2022 17.4 p1
The text was updated successfully, but these errors were encountered: