< Summary

Information
Class: Elsa.Persistence.EFCore.Extensions.QueryableExtensions
Assembly: Elsa.Persistence.EFCore.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Common/Extensions/QueryableExtensions.cs
Line coverage
29%
Covered lines: 5
Uncovered lines: 12
Coverable lines: 17
Total lines: 51
Line coverage: 29.4%
Branch coverage
11%
Covered branches: 2
Total branches: 18
Branch coverage: 11.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
BulkInsertAsync()100%22100%
PaginateAsync()0%7280%
PaginateAsync()0%7280%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Common/Extensions/QueryableExtensions.cs

#LineLine coverage
 1using System.Linq.Expressions;
 2using Elsa.Common.Models;
 3using JetBrains.Annotations;
 4using Microsoft.EntityFrameworkCore;
 5
 6// ReSharper disable once CheckNamespace
 7namespace Elsa.Persistence.EFCore.Extensions;
 8
 9/// <summary>
 10/// Provides extensions to <see cref="IQueryable{T}"/>.
 11/// </summary>
 12[PublicAPI]
 13public static class QueryableExtensions
 14{
 15    /// <summary>
 16    /// Inserts a list of entities in bulk.
 17    /// </summary>
 18    public static async Task BulkInsertAsync<TDbContext, TEntity>(this TDbContext dbContext, IList<TEntity> entities, Ca
 19    {
 32320        var set = dbContext.Set<TEntity>();
 21
 32322        if (entities.Any())
 32323            await set.AddRangeAsync(entities, cancellationToken);
 24
 32325        await dbContext.SaveChangesAsync(cancellationToken);
 32326    }
 27
 28    /// <summary>
 29    /// Returns a paged result from the specified query.
 30    /// </summary>
 31    public static async Task<Page<TTarget>> PaginateAsync<T, TTarget>(this IQueryable<T> queryable, Expression<Func<T, T
 32    {
 033        var count = await queryable.CountAsync();
 034        if (pageArgs?.Offset != null) queryable = queryable.Skip(pageArgs.Offset.Value);
 035        if (pageArgs?.Limit != null) queryable = queryable.Take(pageArgs.Limit.Value);
 036        var results = await queryable.Select(projection).ToListAsync();
 037        return Page.Of(results, count);
 038    }
 39
 40    /// <summary>
 41    /// Returns a paged result from the specified query.
 42    /// </summary>
 43    public static async Task<Page<T>> PaginateAsync<T>(this IQueryable<T> queryable, PageArgs? pageArgs = null)
 44    {
 045        var count = await queryable.CountAsync();
 046        if (pageArgs?.Offset != null) queryable = queryable.Skip(pageArgs.Offset.Value);
 047        if (pageArgs?.Limit != null) queryable = queryable.Take(pageArgs.Limit.Value);
 048        var results = await queryable.ToListAsync();
 049        return Page.Of(results, count);
 050    }
 51}