Skip to content

Projection middleware checks for null on non-nullable field, resulting in exception for complex type in EF Core 8 #6604

@glen-84

Description

@glen-84

Is there an existing issue for this?

  • I have searched the existing issues

Product

Hot Chocolate

Describe the bug

The projection middleware is generating this query:

DbSet<User>()
    .Where(u => u.Id == __query_EntityId_0)
    .Select(_s1 => new User{
        Id = _s1.Id,
        Username = _s1.Username,
        EmailAddress = _s1.EmailAddress,
        AccountStatus = _s1.AccountStatus != null ? new UserAccountStatus{ IsRegistrationCompleted = _s1.AccountStatus.IsRegistrationCompleted }
         : null
    }
    )

Which results in an EF Core 8 exception when using complex types:

System.InvalidOperationException: Comparing complex types to null is not supported.

User.AccountStatus is non-nullable, so it shouldn't be checking for null like this.

Steps to reproduce

I'll provide a reproduction repository if it helps, but it's probably not necessary.

Relevant log output

No response

Additional Context?

No response

Version

13.5.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions