Skip to content

Distinct on Composite User Type property fails #2856

Closed
@PleasantD

Description

@PleasantD

This is a regression introduced in v5.3.0

If I define an ICompositeUserType that directly maps properties to columns, the LINQ query should act on the mapped type's columns.

Say I define PhoneNumber with Number and Ext properties and map them to separate columns.

Prior to v5.3.0 the following worked

using (var s = OpenSession())
{
    s.Save(new Entity { 
        Name = "Company",
        Phone = new PhoneNumber("745-555-1234"),
    });
    s.Save(new Entity
    {
        Name = "Bob",
        Phone = new PhoneNumber("745-555-1234", "x123"),
    });
    s.Save(new Entity
    {
        Name = "Jane",
        Phone = new PhoneNumber("745-555-1235"),
    });
    s.Flush();
}

using (var s = OpenSession())
{
    var numbers = s.Query<Entity>().Select(x => x.Phone.Number).Distinct().ToList();
    Assert.That(numbers.Count, Is.EqualTo(2));
}

After v5.3.0 the Count returned is 3.

Inspecting the SQL generated reveals that both columns of the composite type are being included in the generated SQL rather than the single selected column and thus the DISTINCT clause is returning unexpected results.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions