Skip to content

AsCount is broken when Distinct is used #749

Answered by fairking
fairking asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, I've found that providing a list of columns back to the query solves the problem. Can someone explain why do we replace a list of columns with * when we do AsCount. Just trying to understand whether there is a catch.

My solution was to include all the select columns back to the query. I hope it could help others with the same issue.

var query = new Query("Users")
    .Distinct()
    .Select("Users.Gender", "Roles.Name")
    .Join("Roles", "Users.Role", "Roles.Id");

query.AsCount(query.GetComponents<Column>("select").Select(x => x.Name).ToArray());

As a result I created a helper method which allows to use AsCount in such way:

        public static Query AsCountWithColumns(this Query q…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by fairking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant