Skip to content

4.0.0: Not finding source generated containing type #127

@schoder-moreno

Description

@schoder-moreno

Getting the following exception when using EntityFrameworkCore.Projectables V4.0.0:

Unhandled exception. System.InvalidOperationException: Unable to resolve generated expression for ProjectableV4.PersonExtensions.IsOwner.
   at EntityFrameworkCore.Projectables.Services.ProjectionExpressionResolver.FindGeneratedExpression(MemberInfo projectableMemberInfo)
   at EntityFrameworkCore.Projectables.Services.ProjectableExpressionReplacer.TryGetReflectedExpression(MemberInfo memberInfo, LambdaExpression& reflectedExpression)
   at EntityFrameworkCore.Projectables.Services.ProjectableExpressionReplacer.VisitMethodCall(MethodCallExpression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression`1 node)
   at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)
   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at EntityFrameworkCore.Projectables.Services.ProjectableExpressionReplacer.VisitMethodCall(MethodCallExpression node)
   at EntityFrameworkCore.Projectables.Services.ProjectableExpressionReplacer.Replace(Expression node)
   at EntityFrameworkCore.Projectables.Infrastructure.Internal.CustomQueryCompiler.Expand(Expression expression)
   at EntityFrameworkCore.Projectables.Infrastructure.Internal.CustomQueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at ProjectableV4.Program.Main(String[] args) in (...)/ProjectablesBug/ProjectableV4/Program.cs:line 15

when running this code:

class Program
{
    static void Main(string[] args)
    {
        var dataContext = GetDataContext();

        var result = dataContext.Persons.FirstOrDefault(x => x.IsOwner()); //throws
        var generatedContainingTypeName = Assembly.GetExecutingAssembly().GetType("EntityFrameworkCore.Projectables.Generated.ProjectableV4_PersonExtensions_IsOwner"); // null
    }

    private static DataContext GetDataContext()
    {
        var dboptions = new DbContextOptionsBuilder<DataContext>();
        dboptions.UseInMemoryDatabase("InMemoryDatabase");
        dboptions.UseProjectables();

        return new DataContext(dboptions.Options);
    }
}

public class DataContext(DbContextOptions<DataContext> options) : DbContext(options)
{
    public DbSet<Person> Persons { get; set; }
}

public class Person
{
    public Guid Id { get; set; }
    public string Type { get; set; }
}

public static class PersonExtensions
{
    [Projectable]
    public static bool IsOwner(this Person person) => person.Type == "O";
}

Am I doing something wrong or is there a bug here? Interestingly, the code runs just fine if I use version 3.0.4 instead:

    static void Main(string[] args)
    {
        var dataContext = GetDataContext();

        var result = dataContext.Persons.FirstOrDefault(x => x.IsOwner()); // does not throw
        var generatedContainingTypeName = Assembly.GetExecutingAssembly().GetType("EntityFrameworkCore.Projectables.Generated.ProjectableV3_PersonExtensions_IsOwner"); // not null
    }

See attached MRE.

ProjectablesBug.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions