@@ -26,7 +26,6 @@ public class Specification<T, TResult> : Specification<T>, ISpecification<T, TRe
2626/// <inheritdoc cref="ISpecification{T}"/>
2727public class Specification < T > : ISpecification < T >
2828{
29- private const int DEFAULT_CAPACITY_WHERE = 2 ;
3029 private const int DEFAULT_CAPACITY_SEARCH = 2 ;
3130 private const int DEFAULT_CAPACITY_ORDER = 2 ;
3231 private const int DEFAULT_CAPACITY_INCLUDE = 2 ;
@@ -42,7 +41,7 @@ public class Specification<T> : ISpecification<T>
4241
4342 // The state is null initially, but we're spending 8 bytes per reference (on x64).
4443 // This will be reconsidered for version 10 where we may store the whole state as a single array of structs.
45- private List < WhereExpressionInfo < T > > ? _whereExpressions ;
44+ private OneOrMany < WhereExpressionInfo < T > > _whereExpressions = new ( ) ;
4645 private List < SearchExpressionInfo < T > > ? _searchExpressions ;
4746 private List < OrderExpressionInfo < T > > ? _orderExpressions ;
4847 private List < IncludeExpressionInfo > ? _includeExpressions ;
@@ -94,7 +93,7 @@ public class Specification<T> : ISpecification<T>
9493
9594
9695 // Specs are not intended to be thread-safe, so we don't need to worry about thread-safety here.
97- internal void Add ( WhereExpressionInfo < T > whereExpression ) => ( _whereExpressions ??= new ( DEFAULT_CAPACITY_WHERE ) ) . Add ( whereExpression ) ;
96+ internal void Add ( WhereExpressionInfo < T > whereExpression ) => _whereExpressions . Add ( whereExpression ) ;
9897 internal void Add ( OrderExpressionInfo < T > orderExpression ) => ( _orderExpressions ??= new ( DEFAULT_CAPACITY_ORDER ) ) . Add ( orderExpression ) ;
9998 internal void Add ( IncludeExpressionInfo includeExpression ) => ( _includeExpressions ??= new ( DEFAULT_CAPACITY_INCLUDE ) ) . Add ( includeExpression ) ;
10099 internal void Add ( string includeString ) => ( _includeStrings ??= new ( DEFAULT_CAPACITY_INCLUDESTRING ) ) . Add ( includeString ) ;
@@ -125,7 +124,7 @@ internal void Add(SearchExpressionInfo<T> searchExpression)
125124 public Dictionary < string , object > Items => _items ??= [ ] ;
126125
127126 /// <inheritdoc/>
128- public IEnumerable < WhereExpressionInfo < T > > WhereExpressions => _whereExpressions ?? Enumerable . Empty < WhereExpressionInfo < T > > ( ) ;
127+ public IEnumerable < WhereExpressionInfo < T > > WhereExpressions => _whereExpressions . Values ;
129128
130129 /// <inheritdoc/>
131130 public IEnumerable < SearchExpressionInfo < T > > SearchCriterias => _searchExpressions ?? Enumerable . Empty < SearchExpressionInfo < T > > ( ) ;
@@ -142,6 +141,7 @@ internal void Add(SearchExpressionInfo<T> searchExpression)
142141 /// <inheritdoc/>
143142 public IEnumerable < string > QueryTags => _queryTags . Values ;
144143
144+ internal OneOrMany < WhereExpressionInfo < T > > OneOrManyWhereExpressions => _whereExpressions ;
145145 internal OneOrMany < string > OneOrManyQueryTags => _queryTags ;
146146
147147 /// <inheritdoc/>
@@ -174,9 +174,9 @@ void ISpecification<T>.CopyTo(Specification<T> otherSpec)
174174 // The expression containers are immutable, having the same instance is fine.
175175 // We'll just create new collections.
176176
177- if ( _whereExpressions is not null )
177+ if ( ! _whereExpressions . IsEmpty )
178178 {
179- otherSpec . _whereExpressions = _whereExpressions . ToList ( ) ;
179+ otherSpec . _whereExpressions = _whereExpressions . Clone ( ) ;
180180 }
181181
182182 if ( _includeExpressions is not null )
0 commit comments