@@ -27,8 +27,6 @@ public class Specification<T, TResult> : Specification<T>, ISpecification<T, TRe
2727public class Specification < T > : ISpecification < T >
2828{
2929 private const int DEFAULT_CAPACITY_SEARCH = 2 ;
30- private const int DEFAULT_CAPACITY_INCLUDE = 2 ;
31- private const int DEFAULT_CAPACITY_INCLUDESTRING = 1 ;
3230
3331 // It is utilized only during the building stage for the sub-chains. Once the state is built, we don't care about it anymore.
3432 // The initial value is not important since the value is always initialized by the root of the chain.
@@ -43,8 +41,8 @@ public class Specification<T> : ISpecification<T>
4341 private OneOrMany < WhereExpressionInfo < T > > _whereExpressions = new ( ) ;
4442 private List < SearchExpressionInfo < T > > ? _searchExpressions ;
4543 private OneOrMany < OrderExpressionInfo < T > > _orderExpressions = new ( ) ;
46- private List < IncludeExpressionInfo > ? _includeExpressions ;
47- private List < string > ? _includeStrings ;
44+ private OneOrMany < IncludeExpressionInfo > _includeExpressions = new ( ) ;
45+ private OneOrMany < string > _includeStrings = new ( ) ;
4846 private Dictionary < string , object > ? _items ;
4947 private OneOrMany < string > _queryTags = new ( ) ;
5048
@@ -94,8 +92,8 @@ public class Specification<T> : ISpecification<T>
9492 // Specs are not intended to be thread-safe, so we don't need to worry about thread-safety here.
9593 internal void Add ( WhereExpressionInfo < T > whereExpression ) => _whereExpressions . Add ( whereExpression ) ;
9694 internal void Add ( OrderExpressionInfo < T > orderExpression ) => _orderExpressions . Add ( orderExpression ) ;
97- internal void Add ( IncludeExpressionInfo includeExpression ) => ( _includeExpressions ??= new ( DEFAULT_CAPACITY_INCLUDE ) ) . Add ( includeExpression ) ;
98- internal void Add ( string includeString ) => ( _includeStrings ??= new ( DEFAULT_CAPACITY_INCLUDESTRING ) ) . Add ( includeString ) ;
95+ internal void Add ( IncludeExpressionInfo includeExpression ) => _includeExpressions . Add ( includeExpression ) ;
96+ internal void Add ( string includeString ) => _includeStrings . Add ( includeString ) ;
9997 internal void Add ( SearchExpressionInfo < T > searchExpression )
10098 {
10199 if ( _searchExpressions is null )
@@ -132,16 +130,18 @@ internal void Add(SearchExpressionInfo<T> searchExpression)
132130 public IEnumerable < OrderExpressionInfo < T > > OrderExpressions => _orderExpressions . Values ;
133131
134132 /// <inheritdoc/>
135- public IEnumerable < IncludeExpressionInfo > IncludeExpressions => _includeExpressions ?? Enumerable . Empty < IncludeExpressionInfo > ( ) ;
133+ public IEnumerable < IncludeExpressionInfo > IncludeExpressions => _includeExpressions . Values ;
136134
137135 /// <inheritdoc/>
138- public IEnumerable < string > IncludeStrings => _includeStrings ?? Enumerable . Empty < string > ( ) ;
136+ public IEnumerable < string > IncludeStrings => _includeStrings . Values ;
139137
140138 /// <inheritdoc/>
141139 public IEnumerable < string > QueryTags => _queryTags . Values ;
142140
143141 internal OneOrMany < WhereExpressionInfo < T > > OneOrManyWhereExpressions => _whereExpressions ;
144142 internal OneOrMany < OrderExpressionInfo < T > > OneOrManyOrderExpressions => _orderExpressions ;
143+ internal OneOrMany < IncludeExpressionInfo > OneOrManyIncludeExpressions => _includeExpressions ;
144+ internal OneOrMany < string > OneOrManyIncludeStrings => _includeStrings ;
145145 internal OneOrMany < string > OneOrManyQueryTags => _queryTags ;
146146
147147 /// <inheritdoc/>
@@ -179,14 +179,14 @@ void ISpecification<T>.CopyTo(Specification<T> otherSpec)
179179 otherSpec . _whereExpressions = _whereExpressions . Clone ( ) ;
180180 }
181181
182- if ( _includeExpressions is not null )
182+ if ( ! _includeExpressions . IsEmpty )
183183 {
184- otherSpec . _includeExpressions = _includeExpressions . ToList ( ) ;
184+ otherSpec . _includeExpressions = _includeExpressions . Clone ( ) ;
185185 }
186186
187- if ( _includeStrings is not null )
187+ if ( ! _includeStrings . IsEmpty )
188188 {
189- otherSpec . _includeStrings = _includeStrings . ToList ( ) ;
189+ otherSpec . _includeStrings = _includeStrings . Clone ( ) ;
190190 }
191191
192192 if ( ! _orderExpressions . IsEmpty )
0 commit comments