• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / FluentCommand / 23278216331

19 Mar 2026 03:19AM UTC coverage: 57.398% (+0.7%) from 56.658%
23278216331

push

github

pwelter34
Enable nullable and improve source generators

1403 of 3069 branches covered (45.72%)

Branch coverage included in aggregate %.

527 of 907 new or added lines in 58 files covered. (58.1%)

22 existing lines in 10 files now uncovered.

4288 of 6846 relevant lines covered (62.64%)

330.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/FluentCommand/Query/OrderEntityBuilder.cs
1
using System.Linq.Expressions;
2

3
using FluentCommand.Query.Generators;
4
using FluentCommand.Reflection;
5

6
namespace FluentCommand.Query;
7

8
/// <summary>
9
/// Provides a builder for constructing SQL ORDER BY clauses for a specific entity type with fluent, chainable methods.
10
/// </summary>
11
/// <typeparam name="TEntity">The type of the entity.</typeparam>
12
public class OrderEntityBuilder<TEntity> : OrderBuilder<OrderEntityBuilder<TEntity>>
13
    where TEntity : class
14
{
15
    private static readonly TypeAccessor _typeAccessor = TypeAccessor.GetAccessor<TEntity>();
×
16

17
    /// <summary>
18
    /// Initializes a new instance of the <see cref="OrderEntityBuilder{TEntity}"/> class.
19
    /// </summary>
20
    /// <param name="queryGenerator">The <see cref="IQueryGenerator"/> used to generate SQL expressions.</param>
21
    /// <param name="parameters">The list of <see cref="QueryParameter"/> objects for the query.</param>
22
    public OrderEntityBuilder(IQueryGenerator queryGenerator, List<QueryParameter> parameters)
23
        : base(queryGenerator, parameters)
×
24
    {
25
    }
×
26

27
    /// <summary>
28
    /// Adds an ORDER BY clause with the specified entity property and sort direction.
29
    /// </summary>
30
    /// <typeparam name="TValue">The type of the property value.</typeparam>
31
    /// <param name="property">An expression selecting the property to sort by.</param>
32
    /// <param name="sortDirection">The sort direction (default is <see cref="SortDirections.Ascending"/>).</param>
33
    /// <returns>
34
    /// The same builder instance for method chaining.
35
    /// </returns>
36
    public OrderEntityBuilder<TEntity> OrderBy<TValue>(
37
        Expression<Func<TEntity, TValue>> property,
38
        SortDirections sortDirection = SortDirections.Ascending)
39
    {
NEW
40
        var propertyAccessor = GetPropertyAccessor(property);
×
41

42
        return OrderBy(propertyAccessor.Column, null, sortDirection);
×
43
    }
44

45
    /// <summary>
46
    /// Adds an ORDER BY clause with the specified entity property, sort direction, and table alias.
47
    /// </summary>
48
    /// <typeparam name="TValue">The type of the property value.</typeparam>
49
    /// <param name="property">An expression selecting the property to sort by.</param>
50
    /// <param name="tableAlias">The alias of the table (optional).</param>
51
    /// <param name="sortDirection">The sort direction (default is <see cref="SortDirections.Ascending"/>).</param>
52
    /// <returns>
53
    /// The same builder instance for method chaining.
54
    /// </returns>
55
    public OrderEntityBuilder<TEntity> OrderBy<TValue>(
56
        Expression<Func<TEntity, TValue>> property,
57
        string? tableAlias,
58
        SortDirections sortDirection = SortDirections.Ascending)
59
    {
NEW
60
        var propertyAccessor = GetPropertyAccessor(property);
×
61

62
        return OrderBy(propertyAccessor.Column, tableAlias, sortDirection);
×
63
    }
64

65
    /// <summary>
66
    /// Conditionally adds an ORDER BY clause with the specified entity property, sort direction, and table alias.
67
    /// </summary>
68
    /// <typeparam name="TValue">The type of the property value.</typeparam>
69
    /// <param name="property">An expression selecting the property to sort by.</param>
70
    /// <param name="tableAlias">The alias of the table (optional).</param>
71
    /// <param name="sortDirection">The sort direction (default is <see cref="SortDirections.Ascending"/>).</param>
72
    /// <param name="condition">A function that determines whether to add the ORDER BY clause, based on the property name. If <c>null</c>, the clause is always added.</param>
73
    /// <returns>
74
    /// The same builder instance for method chaining.
75
    /// </returns>
76
    public OrderEntityBuilder<TEntity> OrderByIf<TValue>(
77
        Expression<Func<TEntity, TValue>> property,
78
        string? tableAlias = null,
79
        SortDirections sortDirection = SortDirections.Ascending,
80
        Func<string, bool>? condition = null)
81
    {
NEW
82
        var propertyAccessor = GetPropertyAccessor(property);
×
83

84
        return OrderByIf(propertyAccessor.Column, tableAlias, sortDirection, condition);
×
85
    }
86

87
    private static IMemberAccessor GetPropertyAccessor<TValue>(Expression<Func<TEntity, TValue>> property)
88
    {
NEW
89
        var propertyAccessor = _typeAccessor.FindProperty(property);
×
NEW
90
        if (propertyAccessor is null)
×
NEW
91
            throw new ArgumentException("The specified property does not exist on the entity.", nameof(property));
×
92

NEW
93
        return propertyAccessor;
×
94
    }
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc