Well, I am almost sure that it worked someday in the past.
But, now here is the workaround to achieve the same result.
I have to do a subquery.
Code:
1 PosicaoCotistaQuery posicaoCotistaQuery = new PosicaoCotistaQuery("p");
2 PosicaoCotistaQuery posicaoCotistaSubQuery = new PosicaoCotistaQuery("p1");
3
4 string column = "<count(distinct sub." + PosicaoCotistaMetadata.ColumnNames.IdCotista + ") as IdCotista>";
5
6 posicaoCotistaQuery.Select("" + column + "");
7 //
8 posicaoCotistaQuery.From
9 (
10 posicaoCotistaSubQuery.Select(posicaoCotistaSubQuery.IdCarteira,
11 posicaoCotistaSubQuery.IdCotista,
12 (posicaoCotistaSubQuery.Quantidade + posicaoCotistaSubQuery.QuantidadeBloqueada).As("Quantidade"))
13 .Where(posicaoCotistaSubQuery.IdCarteira == idCarteira &
14 posicaoCotistaSubQuery.Quantidade != 0)
15 ).As("sub");
16
17 PosicaoCotistaCollection posicaoCotistaCollection = new PosicaoCotistaCollection();
18 posicaoCotistaCollection.Load(posicaoCotistaQuery);
19