| | 1 | | namespace Pozitron.QuerySpecification; |
| | 2 | |
|
| | 3 | | public static partial class SpecificationBuilderExtensions |
| | 4 | | { |
| | 5 | | /// <summary> |
| | 6 | | /// Adds an Include clause to the specification. |
| | 7 | | /// </summary> |
| | 8 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | 9 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | 10 | | /// <param name="builder">The specification builder.</param> |
| | 11 | | /// <param name="includeString">The include string.</param> |
| | 12 | | /// <returns>The updated specification builder.</returns> |
| | 13 | | public static ISpecificationBuilder<T, TResult> Include<T, TResult>( |
| | 14 | | this ISpecificationBuilder<T, TResult> builder, |
| | 15 | | string includeString) where T : class |
| 7 | 16 | | => Include(builder, includeString, true); |
| | 17 | |
|
| | 18 | | /// <summary> |
| | 19 | | /// Adds an Include clause to the specification if the condition is true. |
| | 20 | | /// </summary> |
| | 21 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | 22 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | 23 | | /// <param name="builder">The specification builder.</param> |
| | 24 | | /// <param name="includeString">The include string.</param> |
| | 25 | | /// <param name="condition">The condition to evaluate.</param> |
| | 26 | | /// <returns>The updated specification builder.</returns> |
| | 27 | | public static ISpecificationBuilder<T, TResult> Include<T, TResult>( |
| | 28 | | this ISpecificationBuilder<T, TResult> builder, |
| | 29 | | string includeString, |
| | 30 | | bool condition) where T : class |
| | 31 | | { |
| 8 | 32 | | if (condition) |
| | 33 | | { |
| 7 | 34 | | builder.Specification.AddInternal(ItemType.IncludeString, includeString); |
| | 35 | | } |
| 8 | 36 | | return builder; |
| | 37 | | } |
| | 38 | |
|
| | 39 | | /// <summary> |
| | 40 | | /// Adds an Include clause to the specification. |
| | 41 | | /// </summary> |
| | 42 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | 43 | | /// <param name="builder">The specification builder.</param> |
| | 44 | | /// <param name="includeString">The include string.</param> |
| | 45 | | /// <returns>The updated specification builder.</returns> |
| | 46 | | public static ISpecificationBuilder<T> Include<T>( |
| | 47 | | this ISpecificationBuilder<T> builder, |
| | 48 | | string includeString) where T : class |
| 12 | 49 | | => Include(builder, includeString, true); |
| | 50 | |
|
| | 51 | | /// <summary> |
| | 52 | | /// Adds an Include clause to the specification if the condition is true. |
| | 53 | | /// </summary> |
| | 54 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | 55 | | /// <param name="builder">The specification builder.</param> |
| | 56 | | /// <param name="includeString">The include string.</param> |
| | 57 | | /// <param name="condition">The condition to evaluate.</param> |
| | 58 | | /// <returns>The updated specification builder.</returns> |
| | 59 | | public static ISpecificationBuilder<T> Include<T>( |
| | 60 | | this ISpecificationBuilder<T> builder, |
| | 61 | | string includeString, |
| | 62 | | bool condition) where T : class |
| | 63 | | { |
| 13 | 64 | | if (condition) |
| | 65 | | { |
| 12 | 66 | | builder.Specification.AddInternal(ItemType.IncludeString, includeString); |
| | 67 | | } |
| 13 | 68 | | return builder; |
| | 69 | | } |
| | 70 | |
|
| | 71 | | /// <summary> |
| | 72 | | /// Adds an Include clause to the specification. |
| | 73 | | /// </summary> |
| | 74 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | 75 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | 76 | | /// <typeparam name="TProperty">The type of the property.</typeparam> |
| | 77 | | /// <param name="builder">The specification builder.</param> |
| | 78 | | /// <param name="navigationSelector">The include expression.</param> |
| | 79 | | /// <returns>The updated includable specification builder.</returns> |
| | 80 | | public static IIncludableSpecificationBuilder<T, TResult, TProperty> Include<T, TResult, TProperty>( |
| | 81 | | this ISpecificationBuilder<T, TResult> builder, |
| | 82 | | Expression<Func<T, TProperty>> navigationSelector) where T : class |
| 24 | 83 | | => Include(builder, navigationSelector, true); |
| | 84 | |
|
| | 85 | | /// <summary> |
| | 86 | | /// Adds an Include clause to the specification if the condition is true. |
| | 87 | | /// </summary> |
| | 88 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | 89 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | 90 | | /// <typeparam name="TProperty">The type of the property.</typeparam> |
| | 91 | | /// <param name="builder">The specification builder.</param> |
| | 92 | | /// <param name="navigationSelector">The include expression.</param> |
| | 93 | | /// <param name="condition">The condition to evaluate.</param> |
| | 94 | | /// <returns>The updated includable specification builder.</returns> |
| | 95 | | public static IIncludableSpecificationBuilder<T, TResult, TProperty> Include<T, TResult, TProperty>( |
| | 96 | | this ISpecificationBuilder<T, TResult> builder, |
| | 97 | | Expression<Func<T, TProperty>> navigationSelector, |
| | 98 | | bool condition) where T : class |
| | 99 | | { |
| 29 | 100 | | if (condition) |
| | 101 | | { |
| 24 | 102 | | builder.Specification.AddInternal(ItemType.Include, navigationSelector, (int)IncludeType.Include); |
| | 103 | | } |
| | 104 | |
|
| 29 | 105 | | Specification<T, TResult>.IsChainDiscarded = !condition; |
| 29 | 106 | | var includeBuilder = new IncludableSpecificationBuilder<T, TResult, TProperty>(builder.Specification); |
| 29 | 107 | | return includeBuilder; |
| | 108 | | } |
| | 109 | |
|
| | 110 | | /// <summary> |
| | 111 | | /// Adds an Include clause to the specification. |
| | 112 | | /// </summary> |
| | 113 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | 114 | | /// <typeparam name="TProperty">The type of the property.</typeparam> |
| | 115 | | /// <param name="builder">The specification builder.</param> |
| | 116 | | /// <param name="navigationSelector">The include expression.</param> |
| | 117 | | /// <returns>The updated includable specification builder.</returns> |
| | 118 | | public static IIncludableSpecificationBuilder<T, TProperty> Include<T, TProperty>( |
| | 119 | | this ISpecificationBuilder<T> builder, |
| | 120 | | Expression<Func<T, TProperty>> navigationSelector) where T : class |
| 37 | 121 | | => Include(builder, navigationSelector, true); |
| | 122 | |
|
| | 123 | | /// <summary> |
| | 124 | | /// Adds an Include clause to the specification if the condition is true. |
| | 125 | | /// </summary> |
| | 126 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | 127 | | /// <typeparam name="TProperty">The type of the property.</typeparam> |
| | 128 | | /// <param name="builder">The specification builder.</param> |
| | 129 | | /// <param name="navigationSelector">The include expression.</param> |
| | 130 | | /// <param name="condition">The condition to evaluate.</param> |
| | 131 | | /// <returns>The updated includable specification builder.</returns> |
| | 132 | | public static IIncludableSpecificationBuilder<T, TProperty> Include<T, TProperty>( |
| | 133 | | this ISpecificationBuilder<T> builder, |
| | 134 | | Expression<Func<T, TProperty>> navigationSelector, |
| | 135 | | bool condition) where T : class |
| | 136 | | { |
| 42 | 137 | | if (condition) |
| | 138 | | { |
| 37 | 139 | | builder.Specification.AddInternal(ItemType.Include, navigationSelector, (int)IncludeType.Include); |
| | 140 | | } |
| | 141 | |
|
| 42 | 142 | | Specification<T>.IsChainDiscarded = !condition; |
| 42 | 143 | | var includeBuilder = new IncludableSpecificationBuilder<T, TProperty>(builder.Specification); |
| 42 | 144 | | return includeBuilder; |
| | 145 | | } |
| | 146 | |
|
| | 147 | | /// <summary> |
| | 148 | | /// Adds a ThenInclude clause to the specification. |
| | 149 | | /// </summary> |
| | 150 | | /// <typeparam name="TEntity">The type of the entity.</typeparam> |
| | 151 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | 152 | | /// <typeparam name="TPreviousProperty">The type of the previous property.</typeparam> |
| | 153 | | /// <typeparam name="TProperty">The type of the property.</typeparam> |
| | 154 | | /// <param name="builder">The previous includable specification builder.</param> |
| | 155 | | /// <param name="navigationSelector">The include expression.</param> |
| | 156 | | /// <returns>The updated includable specification builder.</returns> |
| | 157 | | public static IIncludableSpecificationBuilder<TEntity, TResult, TProperty> ThenInclude<TEntity, TResult, TPreviousPr |
| | 158 | | this IIncludableSpecificationBuilder<TEntity, TResult, TPreviousProperty> builder, |
| | 159 | | Expression<Func<TPreviousProperty, TProperty>> navigationSelector) |
| | 160 | | where TEntity : class |
| 15 | 161 | | => ThenInclude(builder, navigationSelector, true); |
| | 162 | |
|
| | 163 | | /// <summary> |
| | 164 | | /// Adds a ThenInclude clause to the specification if the condition is true. |
| | 165 | | /// </summary> |
| | 166 | | /// <typeparam name="TEntity">The type of the entity.</typeparam> |
| | 167 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | 168 | | /// <typeparam name="TPreviousProperty">The type of the previous property.</typeparam> |
| | 169 | | /// <typeparam name="TProperty">The type of the property.</typeparam> |
| | 170 | | /// <param name="builder">The previous includable specification builder.</param> |
| | 171 | | /// <param name="navigationSelector">The include expression.</param> |
| | 172 | | /// <param name="condition">The condition to evaluate.</param> |
| | 173 | | /// <returns>The updated includable specification builder.</returns> |
| | 174 | | public static IIncludableSpecificationBuilder<TEntity, TResult, TProperty> ThenInclude<TEntity, TResult, TPreviousPr |
| | 175 | | this IIncludableSpecificationBuilder<TEntity, TResult, TPreviousProperty> builder, |
| | 176 | | Expression<Func<TPreviousProperty, TProperty>> navigationSelector, |
| | 177 | | bool condition) |
| | 178 | | where TEntity : class |
| | 179 | | { |
| 19 | 180 | | if (condition && !Specification<TEntity, TResult>.IsChainDiscarded) |
| | 181 | | { |
| 9 | 182 | | builder.Specification.AddInternal(ItemType.Include, navigationSelector, (int)IncludeType.ThenInclude); |
| | 183 | | } |
| | 184 | | else |
| | 185 | | { |
| 10 | 186 | | Specification<TEntity, TResult>.IsChainDiscarded = true; |
| | 187 | | } |
| | 188 | |
|
| 19 | 189 | | var includeBuilder = new IncludableSpecificationBuilder<TEntity, TResult, TProperty>(builder.Specification); |
| 19 | 190 | | return includeBuilder; |
| | 191 | | } |
| | 192 | |
|
| | 193 | | /// <summary> |
| | 194 | | /// Adds a ThenInclude clause to the specification. |
| | 195 | | /// </summary> |
| | 196 | | /// <typeparam name="TEntity">The type of the entity.</typeparam> |
| | 197 | | /// <typeparam name="TPreviousProperty">The type of the previous property.</typeparam> |
| | 198 | | /// <typeparam name="TProperty">The type of the property.</typeparam> |
| | 199 | | /// <param name="builder">The previous includable specification builder.</param> |
| | 200 | | /// <param name="navigationSelector">The include expression.</param> |
| | 201 | | /// <returns>The updated includable specification builder.</returns> |
| | 202 | | public static IIncludableSpecificationBuilder<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty> |
| | 203 | | this IIncludableSpecificationBuilder<TEntity, TPreviousProperty> builder, |
| | 204 | | Expression<Func<TPreviousProperty, TProperty>> navigationSelector) |
| | 205 | | where TEntity : class |
| 23 | 206 | | => ThenInclude(builder, navigationSelector, true); |
| | 207 | |
|
| | 208 | | /// <summary> |
| | 209 | | /// Adds a ThenInclude clause to the specification if the condition is true. |
| | 210 | | /// </summary> |
| | 211 | | /// <typeparam name="TEntity">The type of the entity.</typeparam> |
| | 212 | | /// <typeparam name="TPreviousProperty">The type of the previous property.</typeparam> |
| | 213 | | /// <typeparam name="TProperty">The type of the property.</typeparam> |
| | 214 | | /// <param name="builder">The previous includable specification builder.</param> |
| | 215 | | /// <param name="navigationSelector">The include expression.</param> |
| | 216 | | /// <param name="condition">The condition to evaluate.</param> |
| | 217 | | /// <returns>The updated includable specification builder.</returns> |
| | 218 | | public static IIncludableSpecificationBuilder<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty> |
| | 219 | | this IIncludableSpecificationBuilder<TEntity, TPreviousProperty> builder, |
| | 220 | | Expression<Func<TPreviousProperty, TProperty>> navigationSelector, |
| | 221 | | bool condition) |
| | 222 | | where TEntity : class |
| | 223 | | { |
| 27 | 224 | | if (condition && !Specification<TEntity>.IsChainDiscarded) |
| | 225 | | { |
| 17 | 226 | | builder.Specification.AddInternal(ItemType.Include, navigationSelector, (int)IncludeType.ThenInclude); |
| | 227 | | } |
| | 228 | | else |
| | 229 | | { |
| 10 | 230 | | Specification<TEntity>.IsChainDiscarded = true; |
| | 231 | | } |
| | 232 | |
|
| 27 | 233 | | var includeBuilder = new IncludableSpecificationBuilder<TEntity, TProperty>(builder.Specification); |
| 27 | 234 | | return includeBuilder; |
| | 235 | | } |
| | 236 | |
|
| | 237 | | /// <summary> |
| | 238 | | /// Adds a ThenInclude clause to the specification. |
| | 239 | | /// </summary> |
| | 240 | | /// <typeparam name="TEntity">The type of the entity.</typeparam> |
| | 241 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | 242 | | /// <typeparam name="TPreviousProperty">The type of the previous property.</typeparam> |
| | 243 | | /// <typeparam name="TProperty">The type of the property.</typeparam> |
| | 244 | | /// <param name="builder">The previous includable specification builder.</param> |
| | 245 | | /// <param name="navigationSelector">The include expression.</param> |
| | 246 | | /// <returns>The updated includable specification builder.</returns> |
| | 247 | | public static IIncludableSpecificationBuilder<TEntity, TResult, TProperty> ThenInclude<TEntity, TResult, TPreviousPr |
| | 248 | | this IIncludableSpecificationBuilder<TEntity, TResult, IEnumerable<TPreviousProperty>> builder, |
| | 249 | | Expression<Func<TPreviousProperty, TProperty>> navigationSelector) |
| | 250 | | where TEntity : class |
| 14 | 251 | | => ThenInclude(builder, navigationSelector, true); |
| | 252 | |
|
| | 253 | | /// <summary> |
| | 254 | | /// Adds a ThenInclude clause to the specification if the condition is true. |
| | 255 | | /// </summary> |
| | 256 | | /// <typeparam name="TEntity">The type of the entity.</typeparam> |
| | 257 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | 258 | | /// <typeparam name="TPreviousProperty">The type of the previous property.</typeparam> |
| | 259 | | /// <typeparam name="TProperty">The type of the property.</typeparam> |
| | 260 | | /// <param name="builder">The previous includable specification builder.</param> |
| | 261 | | /// <param name="navigationSelector">The include expression.</param> |
| | 262 | | /// <param name="condition">The condition to evaluate.</param> |
| | 263 | | /// <returns>The updated includable specification builder.</returns> |
| | 264 | | public static IIncludableSpecificationBuilder<TEntity, TResult, TProperty> ThenInclude<TEntity, TResult, TPreviousPr |
| | 265 | | this IIncludableSpecificationBuilder<TEntity, TResult, IEnumerable<TPreviousProperty>> builder, |
| | 266 | | Expression<Func<TPreviousProperty, TProperty>> navigationSelector, |
| | 267 | | bool condition) |
| | 268 | | where TEntity : class |
| | 269 | | { |
| 18 | 270 | | if (condition && !Specification<TEntity, TResult>.IsChainDiscarded) |
| | 271 | | { |
| 8 | 272 | | builder.Specification.AddInternal(ItemType.Include, navigationSelector, (int)IncludeType.ThenInclude); |
| | 273 | | } |
| | 274 | | else |
| | 275 | | { |
| 10 | 276 | | Specification<TEntity, TResult>.IsChainDiscarded = true; |
| | 277 | | } |
| | 278 | |
|
| 18 | 279 | | var includeBuilder = new IncludableSpecificationBuilder<TEntity, TResult, TProperty>(builder.Specification); |
| 18 | 280 | | return includeBuilder; |
| | 281 | | } |
| | 282 | |
|
| | 283 | | /// <summary> |
| | 284 | | /// Adds a ThenInclude clause to the specification. |
| | 285 | | /// </summary> |
| | 286 | | /// <typeparam name="TEntity">The type of the entity.</typeparam> |
| | 287 | | /// <typeparam name="TPreviousProperty">The type of the previous property.</typeparam> |
| | 288 | | /// <typeparam name="TProperty">The type of the property.</typeparam> |
| | 289 | | /// <param name="builder">The previous includable specification builder.</param> |
| | 290 | | /// <param name="navigationSelector">The include expression.</param> |
| | 291 | | /// <returns>The updated includable specification builder.</returns> |
| | 292 | | public static IIncludableSpecificationBuilder<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty> |
| | 293 | | this IIncludableSpecificationBuilder<TEntity, IEnumerable<TPreviousProperty>> builder, |
| | 294 | | Expression<Func<TPreviousProperty, TProperty>> navigationSelector) |
| | 295 | | where TEntity : class |
| 23 | 296 | | => ThenInclude(builder, navigationSelector, true); |
| | 297 | |
|
| | 298 | | /// <summary> |
| | 299 | | /// Adds a ThenInclude clause to the specification if the condition is true. |
| | 300 | | /// </summary> |
| | 301 | | /// <typeparam name="TEntity">The type of the entity.</typeparam> |
| | 302 | | /// <typeparam name="TPreviousProperty">The type of the previous property.</typeparam> |
| | 303 | | /// <typeparam name="TProperty">The type of the property.</typeparam> |
| | 304 | | /// <param name="builder">The previous includable specification builder.</param> |
| | 305 | | /// <param name="navigationSelector">The include expression.</param> |
| | 306 | | /// <param name="condition">The condition to evaluate.</param> |
| | 307 | | /// <returns>The updated includable specification builder.</returns> |
| | 308 | | public static IIncludableSpecificationBuilder<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty> |
| | 309 | | this IIncludableSpecificationBuilder<TEntity, IEnumerable<TPreviousProperty>> builder, |
| | 310 | | Expression<Func<TPreviousProperty, TProperty>> navigationSelector, |
| | 311 | | bool condition) |
| | 312 | | where TEntity : class |
| | 313 | | { |
| 27 | 314 | | if (condition && !Specification<TEntity>.IsChainDiscarded) |
| | 315 | | { |
| 17 | 316 | | builder.Specification.AddInternal(ItemType.Include, navigationSelector, (int)IncludeType.ThenInclude); |
| | 317 | | } |
| | 318 | | else |
| | 319 | | { |
| 10 | 320 | | Specification<TEntity>.IsChainDiscarded = true; |
| | 321 | | } |
| | 322 | |
|
| 27 | 323 | | var includeBuilder = new IncludableSpecificationBuilder<TEntity, TProperty>(builder.Specification); |
| 27 | 324 | | return includeBuilder; |
| | 325 | | } |
| | 326 | | } |