| | | 1 | | namespace Pozitron.QuerySpecification; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Extension methods for building specifications. |
| | | 5 | | /// </summary> |
| | | 6 | | public static partial class SpecificationBuilderExtensions |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Configures the specification to ignore query filters. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 12 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 13 | | /// <param name="builder">The specification builder.</param> |
| | | 14 | | /// <returns>The updated specification builder.</returns> |
| | | 15 | | public static ISpecificationBuilder<T, TResult> IgnoreQueryFilters<T, TResult>( |
| | | 16 | | this ISpecificationBuilder<T, TResult> builder) where T : class |
| | 5 | 17 | | => IgnoreQueryFilters(builder, true); |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Configures the specification to ignore query filters if the condition is true. |
| | | 21 | | /// </summary> |
| | | 22 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 23 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 24 | | /// <param name="builder">The specification builder.</param> |
| | | 25 | | /// <param name="condition">The condition to evaluate.</param> |
| | | 26 | | /// <returns>The updated specification builder.</returns> |
| | | 27 | | public static ISpecificationBuilder<T, TResult> IgnoreQueryFilters<T, TResult>( |
| | | 28 | | this ISpecificationBuilder<T, TResult> builder, |
| | | 29 | | bool condition) where T : class |
| | | 30 | | { |
| | 6 | 31 | | if (condition) |
| | | 32 | | { |
| | 5 | 33 | | builder.Specification.AddOrUpdateFlag(SpecFlags.IgnoreQueryFilters, true); |
| | | 34 | | } |
| | 6 | 35 | | return builder; |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Configures the specification to ignore query filters. |
| | | 40 | | /// </summary> |
| | | 41 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 42 | | /// <param name="builder">The specification builder.</param> |
| | | 43 | | /// <returns>The updated specification builder.</returns> |
| | | 44 | | public static ISpecificationBuilder<T> IgnoreQueryFilters<T>( |
| | | 45 | | this ISpecificationBuilder<T> builder) where T : class |
| | 18 | 46 | | => IgnoreQueryFilters(builder, true); |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Configures the specification to ignore query filters if the condition is true. |
| | | 50 | | /// </summary> |
| | | 51 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 52 | | /// <param name="builder">The specification builder.</param> |
| | | 53 | | /// <param name="condition">The condition to evaluate.</param> |
| | | 54 | | /// <returns>The updated specification builder.</returns> |
| | | 55 | | public static ISpecificationBuilder<T> IgnoreQueryFilters<T>( |
| | | 56 | | this ISpecificationBuilder<T> builder, |
| | | 57 | | bool condition) where T : class |
| | | 58 | | { |
| | 19 | 59 | | if (condition) |
| | | 60 | | { |
| | 18 | 61 | | builder.Specification.AddOrUpdateFlag(SpecFlags.IgnoreQueryFilters, true); |
| | | 62 | | } |
| | 19 | 63 | | return builder; |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | /// <summary> |
| | | 67 | | /// Configures the specification to ignore auto includes. |
| | | 68 | | /// </summary> |
| | | 69 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 70 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 71 | | /// <param name="builder">The specification builder.</param> |
| | | 72 | | /// <returns>The updated specification builder.</returns> |
| | | 73 | | public static ISpecificationBuilder<T, TResult> IgnoreAutoIncludes<T, TResult>( |
| | | 74 | | this ISpecificationBuilder<T, TResult> builder) where T : class |
| | 1 | 75 | | => IgnoreAutoIncludes(builder, true); |
| | | 76 | | |
| | | 77 | | /// <summary> |
| | | 78 | | /// Configures the specification to ignore auto includes if the condition is true. |
| | | 79 | | /// </summary> |
| | | 80 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 81 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 82 | | /// <param name="builder">The specification builder.</param> |
| | | 83 | | /// <param name="condition">The condition to evaluate.</param> |
| | | 84 | | /// <returns>The updated specification builder.</returns> |
| | | 85 | | public static ISpecificationBuilder<T, TResult> IgnoreAutoIncludes<T, TResult>( |
| | | 86 | | this ISpecificationBuilder<T, TResult> builder, |
| | | 87 | | bool condition) where T : class |
| | | 88 | | { |
| | 2 | 89 | | if (condition) |
| | | 90 | | { |
| | 1 | 91 | | builder.Specification.AddOrUpdateFlag(SpecFlags.IgnoreAutoIncludes, true); |
| | | 92 | | } |
| | 2 | 93 | | return builder; |
| | | 94 | | } |
| | | 95 | | |
| | | 96 | | /// <summary> |
| | | 97 | | /// Configures the specification to ignore auto includes. |
| | | 98 | | /// </summary> |
| | | 99 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 100 | | /// <param name="builder">The specification builder.</param> |
| | | 101 | | /// <returns>The updated specification builder.</returns> |
| | | 102 | | public static ISpecificationBuilder<T> IgnoreAutoIncludes<T>( |
| | | 103 | | this ISpecificationBuilder<T> builder) where T : class |
| | 4 | 104 | | => IgnoreAutoIncludes(builder, true); |
| | | 105 | | |
| | | 106 | | /// <summary> |
| | | 107 | | /// Configures the specification to ignore auto includes if the condition is true. |
| | | 108 | | /// </summary> |
| | | 109 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 110 | | /// <param name="builder">The specification builder.</param> |
| | | 111 | | /// <param name="condition">The condition to evaluate.</param> |
| | | 112 | | /// <returns>The updated specification builder.</returns> |
| | | 113 | | public static ISpecificationBuilder<T> IgnoreAutoIncludes<T>( |
| | | 114 | | this ISpecificationBuilder<T> builder, |
| | | 115 | | bool condition) where T : class |
| | | 116 | | { |
| | 5 | 117 | | if (condition) |
| | | 118 | | { |
| | 4 | 119 | | builder.Specification.AddOrUpdateFlag(SpecFlags.IgnoreAutoIncludes, true); |
| | | 120 | | } |
| | 5 | 121 | | return builder; |
| | | 122 | | } |
| | | 123 | | |
| | | 124 | | /// <summary> |
| | | 125 | | /// Configures the specification to use split queries. |
| | | 126 | | /// </summary> |
| | | 127 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 128 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 129 | | /// <param name="builder">The specification builder.</param> |
| | | 130 | | /// <returns>The updated specification builder.</returns> |
| | | 131 | | public static ISpecificationBuilder<T, TResult> AsSplitQuery<T, TResult>( |
| | | 132 | | this ISpecificationBuilder<T, TResult> builder) where T : class |
| | 1 | 133 | | => AsSplitQuery(builder, true); |
| | | 134 | | |
| | | 135 | | /// <summary> |
| | | 136 | | /// Configures the specification to use split queries if the condition is true. |
| | | 137 | | /// </summary> |
| | | 138 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 139 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 140 | | /// <param name="builder">The specification builder.</param> |
| | | 141 | | /// <param name="condition">The condition to evaluate.</param> |
| | | 142 | | /// <returns>The updated specification builder.</returns> |
| | | 143 | | public static ISpecificationBuilder<T, TResult> AsSplitQuery<T, TResult>( |
| | | 144 | | this ISpecificationBuilder<T, TResult> builder, |
| | | 145 | | bool condition) where T : class |
| | | 146 | | { |
| | 2 | 147 | | if (condition) |
| | | 148 | | { |
| | 1 | 149 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsSplitQuery, true); |
| | | 150 | | } |
| | 2 | 151 | | return builder; |
| | | 152 | | } |
| | | 153 | | |
| | | 154 | | /// <summary> |
| | | 155 | | /// Configures the specification to use split queries. |
| | | 156 | | /// </summary> |
| | | 157 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 158 | | /// <param name="builder">The specification builder.</param> |
| | | 159 | | /// <returns>The updated specification builder.</returns> |
| | | 160 | | public static ISpecificationBuilder<T> AsSplitQuery<T>( |
| | | 161 | | this ISpecificationBuilder<T> builder) where T : class |
| | 12 | 162 | | => AsSplitQuery(builder, true); |
| | | 163 | | |
| | | 164 | | /// <summary> |
| | | 165 | | /// Configures the specification to use split queries if the condition is true. |
| | | 166 | | /// </summary> |
| | | 167 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 168 | | /// <param name="builder">The specification builder.</param> |
| | | 169 | | /// <param name="condition">The condition to evaluate.</param> |
| | | 170 | | /// <returns>The updated specification builder.</returns> |
| | | 171 | | public static ISpecificationBuilder<T> AsSplitQuery<T>( |
| | | 172 | | this ISpecificationBuilder<T> builder, |
| | | 173 | | bool condition) where T : class |
| | | 174 | | { |
| | 13 | 175 | | if (condition) |
| | | 176 | | { |
| | 12 | 177 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsSplitQuery, true); |
| | | 178 | | } |
| | 13 | 179 | | return builder; |
| | | 180 | | } |
| | | 181 | | |
| | | 182 | | /// <summary> |
| | | 183 | | /// Configures the specification to apply NoTracking behavior. |
| | | 184 | | /// It will also disable AsNoTrackingWithIdentityResolution and AsTracking flags. |
| | | 185 | | /// </summary> |
| | | 186 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 187 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 188 | | /// <param name="builder">The specification builder.</param> |
| | | 189 | | /// <returns>The updated specification builder.</returns> |
| | | 190 | | public static ISpecificationBuilder<T, TResult> AsNoTracking<T, TResult>( |
| | | 191 | | this ISpecificationBuilder<T, TResult> builder) where T : class |
| | 1 | 192 | | => AsNoTracking(builder, true); |
| | | 193 | | |
| | | 194 | | /// <summary> |
| | | 195 | | /// Configures the specification to apply NoTracking behavior if the condition is true. |
| | | 196 | | /// It will also disable AsNoTrackingWithIdentityResolution and AsTracking flags. |
| | | 197 | | /// </summary> |
| | | 198 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 199 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 200 | | /// <param name="builder">The specification builder.</param> |
| | | 201 | | /// <param name="condition">The condition to evaluate.</param> |
| | | 202 | | /// <returns>The updated specification builder.</returns> |
| | | 203 | | public static ISpecificationBuilder<T, TResult> AsNoTracking<T, TResult>( |
| | | 204 | | this ISpecificationBuilder<T, TResult> builder, |
| | | 205 | | bool condition) where T : class |
| | | 206 | | { |
| | 2 | 207 | | if (condition) |
| | | 208 | | { |
| | 1 | 209 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsTracking, false); |
| | 1 | 210 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsNoTrackingWithIdentityResolution, false); |
| | 1 | 211 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsNoTracking, true); |
| | | 212 | | } |
| | 2 | 213 | | return builder; |
| | | 214 | | } |
| | | 215 | | |
| | | 216 | | /// <summary> |
| | | 217 | | /// Configures the specification to apply NoTracking behavior. |
| | | 218 | | /// It will also disable AsNoTrackingWithIdentityResolution and AsTracking flags. |
| | | 219 | | /// </summary> |
| | | 220 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 221 | | /// <param name="builder">The specification builder.</param> |
| | | 222 | | /// <returns>The updated specification builder.</returns> |
| | | 223 | | public static ISpecificationBuilder<T> AsNoTracking<T>( |
| | | 224 | | this ISpecificationBuilder<T> builder) where T : class |
| | 16 | 225 | | => AsNoTracking(builder, true); |
| | | 226 | | |
| | | 227 | | /// <summary> |
| | | 228 | | /// Configures the specification to apply NoTracking behavior if the condition is true. |
| | | 229 | | /// It will also disable AsNoTrackingWithIdentityResolution and AsTracking flags. |
| | | 230 | | /// </summary> |
| | | 231 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 232 | | /// <param name="builder">The specification builder.</param> |
| | | 233 | | /// <param name="condition">The condition to evaluate.</param> |
| | | 234 | | /// <returns>The updated specification builder.</returns> |
| | | 235 | | public static ISpecificationBuilder<T> AsNoTracking<T>( |
| | | 236 | | this ISpecificationBuilder<T> builder, |
| | | 237 | | bool condition) where T : class |
| | | 238 | | { |
| | 17 | 239 | | if (condition) |
| | | 240 | | { |
| | 16 | 241 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsTracking, false); |
| | 16 | 242 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsNoTrackingWithIdentityResolution, false); |
| | 16 | 243 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsNoTracking, true); |
| | | 244 | | } |
| | 17 | 245 | | return builder; |
| | | 246 | | } |
| | | 247 | | |
| | | 248 | | /// <summary> |
| | | 249 | | /// Configures the specification to apply AsNoTrackingWithIdentityResolution behavior. |
| | | 250 | | /// It will also disable AsNoTracking and AsTracking flags. |
| | | 251 | | /// </summary> |
| | | 252 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 253 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 254 | | /// <param name="builder">The specification builder.</param> |
| | | 255 | | /// <returns>The updated specification builder.</returns> |
| | | 256 | | public static ISpecificationBuilder<T, TResult> AsNoTrackingWithIdentityResolution<T, TResult>( |
| | | 257 | | this ISpecificationBuilder<T, TResult> builder) where T : class |
| | 1 | 258 | | => AsNoTrackingWithIdentityResolution(builder, true); |
| | | 259 | | |
| | | 260 | | /// <summary> |
| | | 261 | | /// Configures the specification to apply AsNoTrackingWithIdentityResolution behavior if the condition is true. |
| | | 262 | | /// It will also disable AsNoTracking and AsTracking flags. |
| | | 263 | | /// </summary> |
| | | 264 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 265 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 266 | | /// <param name="builder">The specification builder.</param> |
| | | 267 | | /// <param name="condition">The condition to evaluate.</param> |
| | | 268 | | /// <returns>The updated specification builder.</returns> |
| | | 269 | | public static ISpecificationBuilder<T, TResult> AsNoTrackingWithIdentityResolution<T, TResult>( |
| | | 270 | | this ISpecificationBuilder<T, TResult> builder, |
| | | 271 | | bool condition) where T : class |
| | | 272 | | { |
| | 2 | 273 | | if (condition) |
| | | 274 | | { |
| | 1 | 275 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsNoTracking, false); |
| | 1 | 276 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsTracking, false); |
| | 1 | 277 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsNoTrackingWithIdentityResolution, true); |
| | | 278 | | } |
| | 2 | 279 | | return builder; |
| | | 280 | | } |
| | | 281 | | |
| | | 282 | | /// <summary> |
| | | 283 | | /// Configures the specification to apply AsNoTrackingWithIdentityResolution behavior. |
| | | 284 | | /// It will also disable AsNoTracking and AsTracking flags. |
| | | 285 | | /// </summary> |
| | | 286 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 287 | | /// <param name="builder">The specification builder.</param> |
| | | 288 | | /// <returns>The updated specification builder.</returns> |
| | | 289 | | public static ISpecificationBuilder<T> AsNoTrackingWithIdentityResolution<T>( |
| | | 290 | | this ISpecificationBuilder<T> builder) where T : class |
| | 9 | 291 | | => AsNoTrackingWithIdentityResolution(builder, true); |
| | | 292 | | |
| | | 293 | | /// <summary> |
| | | 294 | | /// Configures the specification to apply AsNoTrackingWithIdentityResolution behavior if the condition is true. |
| | | 295 | | /// It will also disable AsNoTracking and AsTracking flags. |
| | | 296 | | /// </summary> |
| | | 297 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 298 | | /// <param name="builder">The specification builder.</param> |
| | | 299 | | /// <param name="condition">The condition to evaluate.</param> |
| | | 300 | | /// <returns>The updated specification builder.</returns> |
| | | 301 | | public static ISpecificationBuilder<T> AsNoTrackingWithIdentityResolution<T>( |
| | | 302 | | this ISpecificationBuilder<T> builder, |
| | | 303 | | bool condition) where T : class |
| | | 304 | | { |
| | 10 | 305 | | if (condition) |
| | | 306 | | { |
| | 9 | 307 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsNoTracking, false); |
| | 9 | 308 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsTracking, false); |
| | 9 | 309 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsNoTrackingWithIdentityResolution, true); |
| | | 310 | | } |
| | 10 | 311 | | return builder; |
| | | 312 | | } |
| | | 313 | | |
| | | 314 | | /// <summary> |
| | | 315 | | /// Configures the specification to apply AsTracking behavior. |
| | | 316 | | /// It will also disable AsNoTrackingWithIdentityResolution and AsNoTracking flags. |
| | | 317 | | /// </summary> |
| | | 318 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 319 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 320 | | /// <param name="builder">The specification builder.</param> |
| | | 321 | | /// <returns>The updated specification builder.</returns> |
| | | 322 | | public static ISpecificationBuilder<T, TResult> AsTracking<T, TResult>( |
| | | 323 | | this ISpecificationBuilder<T, TResult> builder) where T : class |
| | 1 | 324 | | => AsTracking(builder, true); |
| | | 325 | | |
| | | 326 | | /// <summary> |
| | | 327 | | /// Configures the specification to apply AsTracking behavior if the condition is true. |
| | | 328 | | /// It will also disable AsNoTrackingWithIdentityResolution and AsNoTracking flags. |
| | | 329 | | /// </summary> |
| | | 330 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 331 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 332 | | /// <param name="builder">The specification builder.</param> |
| | | 333 | | /// <param name="condition">The condition to evaluate.</param> |
| | | 334 | | /// <returns>The updated specification builder.</returns> |
| | | 335 | | public static ISpecificationBuilder<T, TResult> AsTracking<T, TResult>( |
| | | 336 | | this ISpecificationBuilder<T, TResult> builder, |
| | | 337 | | bool condition) where T : class |
| | | 338 | | { |
| | 2 | 339 | | if (condition) |
| | | 340 | | { |
| | 1 | 341 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsNoTracking, false); |
| | 1 | 342 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsNoTrackingWithIdentityResolution, false); |
| | 1 | 343 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsTracking, true); |
| | | 344 | | } |
| | 2 | 345 | | return builder; |
| | | 346 | | } |
| | | 347 | | |
| | | 348 | | /// <summary> |
| | | 349 | | /// Configures the specification to apply AsTracking behavior. |
| | | 350 | | /// It will also disable AsNoTrackingWithIdentityResolution and AsNoTracking flags. |
| | | 351 | | /// </summary> |
| | | 352 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 353 | | /// <param name="builder">The specification builder.</param> |
| | | 354 | | /// <returns>The updated specification builder.</returns> |
| | | 355 | | public static ISpecificationBuilder<T> AsTracking<T>( |
| | | 356 | | this ISpecificationBuilder<T> builder) where T : class |
| | 9 | 357 | | => AsTracking(builder, true); |
| | | 358 | | |
| | | 359 | | /// <summary> |
| | | 360 | | /// Configures the specification to apply AsTracking behavior if the condition is true. |
| | | 361 | | /// It will also disable AsNoTrackingWithIdentityResolution and AsNoTracking flags. |
| | | 362 | | /// </summary> |
| | | 363 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | | 364 | | /// <param name="builder">The specification builder.</param> |
| | | 365 | | /// <param name="condition">The condition to evaluate.</param> |
| | | 366 | | /// <returns>The updated specification builder.</returns> |
| | | 367 | | public static ISpecificationBuilder<T> AsTracking<T>( |
| | | 368 | | this ISpecificationBuilder<T> builder, |
| | | 369 | | bool condition) where T : class |
| | | 370 | | { |
| | 10 | 371 | | if (condition) |
| | | 372 | | { |
| | 9 | 373 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsNoTracking, false); |
| | 9 | 374 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsNoTrackingWithIdentityResolution, false); |
| | 9 | 375 | | builder.Specification.AddOrUpdateFlag(SpecFlags.AsTracking, true); |
| | | 376 | | } |
| | 10 | 377 | | return builder; |
| | | 378 | | } |
| | | 379 | | } |