File tree Expand file tree Collapse file tree 4 files changed +42
-3
lines changed Expand file tree Collapse file tree 4 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -1132,6 +1132,7 @@ public async Task<int> CountAsync(CancellationToken cancellationToken = default)
11321132 // Clear paging and order when counting
11331133 localBuilder . ClearOrder ( ) ;
11341134 localBuilder . ClearGroupBy ( ) ;
1135+ localBuilder . ClearTrail ( ) ;
11351136 localBuilder . Skip ( null ) ;
11361137 localBuilder . Take ( null ) ;
11371138
Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
3- using System . Linq ;
43using YesSql . Utils ;
54
65namespace YesSql . Sql
@@ -344,7 +343,7 @@ public virtual void Trail(string segment)
344343
345344 public virtual void ClearTrail ( )
346345 {
347- TrailSegments . Clear ( ) ;
346+ _trail ? . Clear ( ) ;
348347 }
349348
350349 public virtual string ToSqlString ( )
@@ -365,7 +364,7 @@ public virtual string ToSqlString()
365364 if ( _order != null )
366365 {
367366 sb . Append ( "ON(" ) ;
368- sb . Append ( OrderSegments . First ( ) ) ;
367+ sb . Append ( OrderSegments [ 0 ] ) ;
369368 sb . Append ( ") " ) ;
370369 }
371370 }
Original file line number Diff line number Diff line change @@ -1043,6 +1043,42 @@ public async Task SavingRefreshedDocument()
10431043 await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => session . SaveAsync ( newBill1 ) ) ;
10441044 }
10451045
1046+ [ Fact ]
1047+ public async Task CountAsync_WhenCalledAfterListAsync_ReturnCorrectTotal ( )
1048+ {
1049+ _store . RegisterIndexes < PersonIndexProvider > ( ) ;
1050+
1051+ await using ( var session = _store . CreateSession ( ) )
1052+ {
1053+ var bill = new Person
1054+ {
1055+ Firstname = "Bill" ,
1056+ Lastname = "Gates"
1057+ } ;
1058+
1059+ var mike = new Person
1060+ {
1061+ Firstname = "Mike" ,
1062+ Lastname = "Alhayek"
1063+ } ;
1064+
1065+ await session . SaveAsync ( bill ) ;
1066+ await session . SaveAsync ( mike ) ;
1067+
1068+ await session . SaveChangesAsync ( ) ;
1069+
1070+ var query = session . Query < Person , PersonByName > ( ) . OrderBy ( x => x . DocumentId ) . Skip ( 1 ) . Take ( 1 ) ;
1071+
1072+ var records = await query . ListAsync ( ) ;
1073+
1074+ Assert . Equal ( 2 , await query . CountAsync ( ) ) ;
1075+
1076+ Assert . Single ( records ) ;
1077+
1078+ Assert . Equal ( "Mike" , records . First ( ) . Firstname ) ;
1079+ }
1080+ }
1081+
10461082 [ Fact ]
10471083 public async Task ShouldUpdateAutoFlushedIndex ( )
10481084 {
Original file line number Diff line number Diff line change @@ -6,7 +6,10 @@ namespace YesSql.Tests.Indexes
66{
77 public class PersonByName : MapIndex
88 {
9+ public long DocumentId { get ; set ; }
10+
911 public string SomeName { get ; set ; }
12+
1013 public static string Normalize ( string name )
1114 {
1215 return name . ToUpperInvariant ( ) ;
You can’t perform that action at this time.
0 commit comments