Skip to content

SqlBuilder: GroupBy / Having randomly added when creating query #573

@MikeKry

Description

@MikeKry

I have run into some unexpected behavior of SqlBuilder.

When I create sql builder from scratch, sometimes it returns empty group by / having clauses from ToSqlString() method.

"SELECT [LocalizedContentItemIndex_a1].[LocalizationSet] FROM [LocalizedContentItemIndex] AS [b] WHERE [b].[Culture] = 'cs-cz' AND [b].[Published] = 1 AND [b].[Published] = 1 AND [LocalizedContentItemIndex_a1].[LocalizationSet] = [b].[LocalizationSet] GROUP BY HAVING "

It can be fixed by calling ClearGroupBy(), which sets internal _group and _having property to null instead of empty array.

image

I do not understand why it happens, as it does happens unpredictably.

Here is full code:
image

It seems that it happens always when sqlBuilder object is viewed in debugger

Fix could be using Count instead of null comparison here

sb.Append(" GROUP BY ");

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