Skip to content

Linq query OrderBy fails when projecting to record type class having primary constructor #3213

Open
@joe-hamilton-wesd

Description

@joe-hamilton-wesd

NHibernate Linq fails to convert OrderBy expression to SQL when projecting to a record type class that has a primary constructor. If I remove the primary constructor of the class I am projecting to then the OrderBy expression works.

//OrderBy fails if object projecting to has primary constructor:
public record SearchCoursesResult(
    Guid CourseId,
    string CourseName,
    Guid SubjectId,
    string SubjectName,
    string CourseLevel,
    string? CollegeCourseCode,
    bool CourseIsActive
    );

//OrderBy succeeds if object projecting to does not have primary constructor
public record SearchCoursesResult
{
    public Guid CourseId { get; init; }
    public string CourseName { get; init; }    
    public Guid SubjectId { get; init; }    
    public string SubjectName { get; init; }    
    public string CourseLevel { get; init; }    
    public string? CollegeCourseCode { get; init; }    
    public bool CourseIsActive { get; init; }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions