Skip to content

Select Error in Entityframework core 3.1.2 #20331

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
hejiajun107 opened this issue Mar 18, 2020 · 6 comments
Closed

Select Error in Entityframework core 3.1.2 #20331

hejiajun107 opened this issue Mar 18, 2020 · 6 comments

Comments

@hejiajun107
Copy link

An error will occur when selct into a complex object "EF.Property called with wrong property name"
image

image

@ajcvickers
Copy link
Contributor

@hejiajun107 Please attach a small, runnable project or post a small, runnable code listing that reproduces the behavior you are seeing so that we can investigate.

@ajcvickers ajcvickers transferred this issue from dotnet/EntityFramework.Docs Mar 18, 2020
@hejiajun107
Copy link
Author

@hejiajun107 Please attach a small, runnable project or post a small, runnable code listing that reproduces the behavior you are seeing so that we can investigate.

The runable demo is as follewed
EFCore3_1.zip

@ajcvickers
Copy link
Contributor

Note for team triage: In-memory provider; AbsolutePathFaceUrl is not mapped.

var data = context
    .Set<Topic>()
    .Where(t => t.Name.Contains("topic"))
    .Include(x => x.Student)
    .OrderByDescending(x => x.Id)
    .Select(x => new
    {
        Topic = x,
        Student = new
        {
            Name = x.Student.Name,
            AbsoluteFaceUrl = x.Student.AbsolutePathFaceUrl
        },
        IsFavored = false
    }).Skip(1).Take(10).ToList();
public class Student
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string FaceUrl { get; set; }

    [NotMapped]
    public string AbsolutePathFaceUrl { 
        get {
            if(string.IsNullOrEmpty(FaceUrl))
            {
                return "";
            }
            return "https://www.baidu.com/" + FaceUrl + "?timespan=" +  DateTime.Now.ToString("yyyyMMddHHmmss");
        }
    }
 }
/usr/share/dotnet/dotnet /home/ajcvickers/repros/EFCore3_1/bin/Debug/netcoreapp3.1/EFCore3_1.dll
Unhandled exception. System.InvalidOperationException: EF.Property called with wrong property name.
   at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryExpressionTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryExpressionTranslatingExpressionVisitor.Translate(Expression expression)
   at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryQueryableMethodTranslatingExpressionVisitor.TranslateExpression(Expression expression, Boolean preserveType)
   at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryQueryableMethodTranslatingExpressionVisitor.TranslateLambdaExpression(ShapedQueryExpression shapedQueryExpression, LambdaExpression lambdaExpression, Boolean preserveType)
   at Microsoft.EntityFrameworkCore.InMemory.Query.Internal.InMemoryQueryableMethodTranslatingExpressionVisitor.TranslateJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   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.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 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 EFCore3_1.Program.Main(String[] args) in /home/ajcvickers/repros/EFCore3_1/Program.cs:line 44

@smitpatel
Copy link
Contributor

@ajcvickers - Can you try on nightlies? We have fixed bunch of issues in nav expansion around unmapped properties in projection followed by skip/take.

@ajcvickers
Copy link
Contributor

@smitpatel The exception is no longer thrown with 5.0 preview 1. Dupe?

@smitpatel
Copy link
Contributor

Probably fixed by #19377, couldn't find specific dupe.

@ajcvickers ajcvickers modified the milestones: 5.0.0, 5.0.0-preview1 Mar 20, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0-preview1, 5.0.0 Nov 7, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants