@@ -75,26 +75,12 @@ public static async Task<PagedResponse<object>> ColumnDistinctValuesAsync<TEntit
7575
7676 if ( ! mapper ! . IsEncrypted ( model . PropertyName ) )
7777 {
78- if ( mapper ! . IsArray ( model . PropertyName ) )
79- {
80-
81- var data = await query . ApplyFiltering ( model , mapper )
82- . ApplySelect ( model . PropertyName , mapper )
83- . ToArrayAsync ( cancellationToken ) ;
84-
85- var result = data . SelectMany ( item => ( ( IList ) item ) . Cast < object > ( ) )
86- . Distinct ( )
87- . OrderBy ( x => x )
88- . ToList ( ) ;
89-
90- return new PagedResponse < object > ( result , model . Page , model . PageSize , result . Count ) ;
91- }
9278
9379 return await query
9480 . ApplyFiltering ( model , mapper )
9581 . ApplySelect ( model . PropertyName , mapper )
9682 . Distinct ( )
97- . OrderBy ( x => x )
83+ . OrderBy ( x => x ?? 0 )
9884 . GetPagedAsync ( model , cancellationToken ) ;
9985 }
10086
@@ -111,6 +97,41 @@ public static async Task<PagedResponse<object>> ColumnDistinctValuesAsync<TEntit
11197 var decryptedItem = decryptor ! ( ( byte [ ] ) item ) ;
11298 return new PagedResponse < object > ( [ decryptedItem ] , 1 , 1 , 1 ) ;
11399 }
100+
101+ public static async Task < CursoredResponse < object > > ColumnDistinctValuesAsync < TEntity > ( this IQueryable < TEntity > query ,
102+ ColumnDistinctValueCursoredQueryModel model , Func < byte [ ] , string > ? decryptor = default ,
103+ CancellationToken cancellationToken = default )
104+ {
105+ var mapper = EntityGridifyMapperByType [ typeof ( TEntity ) ] as FilterMapper < TEntity > ;
106+
107+ var gridifyModel = ColumnDistinctValueCursoredQueryModel . ToGridifyQueryModel ( model ) ;
108+
109+ if ( ! mapper ! . IsEncrypted ( model . PropertyName ) )
110+ {
111+
112+ var result = await query
113+ . ApplyFiltering ( gridifyModel , mapper )
114+ . ApplySelect ( model . PropertyName , mapper )
115+ . Distinct ( )
116+ . OrderBy ( x => x ?? 0 )
117+ . ToListAsync ( cancellationToken : cancellationToken ) ;
118+
119+ return new CursoredResponse < object > ( result , model . PageSize ) ;
120+ }
121+
122+ var item = await query
123+ . ApplyFiltering ( gridifyModel , mapper )
124+ . Select ( CreateSelector < TEntity > ( model . PropertyName ) )
125+ . FirstOrDefaultAsync ( cancellationToken ) ;
126+
127+ if ( item is null )
128+ {
129+ return new CursoredResponse < object > ( [ ] , model . PageSize ) ;
130+ }
131+
132+ var decryptedItem = decryptor ! ( ( byte [ ] ) item ) ;
133+ return new CursoredResponse < object > ( [ decryptedItem ] , model . PageSize ) ;
134+ }
114135
115136 public static async Task < object > AggregateAsync < TEntity > ( this IQueryable < TEntity > query ,
116137 AggregateQueryModel model ,
0 commit comments