@@ -30,7 +30,7 @@ public QueryState(ISqlBuilder sqlBuilder, IStore store, string collection)
3030
3131 public string _bindingName = "a1" ;
3232 public Dictionary < string , List < Type > > _bindings = new Dictionary < string , List < Type > > ( ) ;
33- public readonly string _documentTable ;
33+ public string _documentTable ;
3434 public string _lastParameterName ;
3535 public ISqlBuilder _sqlBuilder ;
3636 public List < Action < object , ISqlBuilder > > _parameterBindings ;
@@ -57,6 +57,11 @@ public void FlushFilters()
5757 _predicate = null ;
5858 }
5959 }
60+ public void SetCurrentCollection ( string collection )
61+ {
62+ _collection = collection ;
63+ _documentTable = _store . Configuration . TableNameConvention . GetDocumentTable ( collection ) ;
64+ }
6065
6166 public string GetTableAlias ( string tableName )
6267 {
@@ -1039,8 +1044,13 @@ public async Task<int> CountAsync()
10391044 }
10401045 }
10411046
1042- IQuery < T > IQuery . For < T > ( bool filterType )
1047+ IQuery < T > IQuery . For < T > ( bool filterType , string collection )
10431048 {
1049+ if ( collection != null )
1050+ {
1051+ _collection = collection ;
1052+ _queryState . SetCurrentCollection ( collection ) ;
1053+ }
10441054 _queryState . GetBindings ( ) . Clear ( ) ;
10451055 _queryState . AddBinding ( typeof ( Document ) ) ;
10461056
@@ -1056,8 +1066,13 @@ IQuery<T> IQuery.For<T>(bool filterType)
10561066 return new Query < T > ( this ) ;
10571067 }
10581068
1059- IQueryIndex < TIndex > IQuery . ForIndex < TIndex > ( )
1069+ IQueryIndex < TIndex > IQuery . ForIndex < TIndex > ( string collection )
10601070 {
1071+ if ( collection != null )
1072+ {
1073+ _collection = collection ;
1074+ _queryState . SetCurrentCollection ( collection ) ;
1075+ }
10611076 _queryState . GetBindings ( ) . Clear ( ) ;
10621077 _queryState . AddBinding ( typeof ( TIndex ) ) ;
10631078 _queryState . _sqlBuilder . Select ( ) ;
0 commit comments