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

loresoft / FluentCommand / 6648415992

26 Oct 2023 01:49AM UTC coverage: 51.645% (+0.1%) from 51.515%
6648415992

push

github

pwelter34
Update InsertBuilder.cs

981 of 2442 branches covered (0.0%)

Branch coverage included in aggregate %.

2896 of 5065 relevant lines covered (57.18%)

156.37 hits per line

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

63.41
/src/FluentCommand/Query/LogicalEntityBuilder.cs
1
using System.Linq.Expressions;
2

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

7
namespace FluentCommand.Query;
8

9
/// <summary>
10
/// A logical query expression builder 
11
/// </summary>
12
/// <typeparam name="TEntity">The type of the entity.</typeparam>
13
public class LogicalEntityBuilder<TEntity>
14
    : LogicalBuilder<LogicalEntityBuilder<TEntity>>, IWhereEntityBuilder<TEntity, LogicalEntityBuilder<TEntity>>
15
    where TEntity : class
16
{
17
    private static readonly TypeAccessor _typeAccessor = TypeAccessor.GetAccessor<TEntity>();
4✔
18

19
    /// <summary>
20
    /// Initializes a new instance of the <see cref="LogicalEntityBuilder{TEntity}"/> class.
21
    /// </summary>
22
    /// <param name="queryGenerator">The query generator.</param>
23
    /// <param name="parameters">The query parameters.</param>
24
    /// <param name="logicalOperator">The query logical operator.</param>
25
    public LogicalEntityBuilder(
26
        IQueryGenerator queryGenerator,
27
        List<QueryParameter> parameters,
28
        LogicalOperators logicalOperator = LogicalOperators.And)
29
        : base(queryGenerator, parameters, logicalOperator)
7✔
30
    {
31
    }
7✔
32

33
    /// <inheritdoc />
34
    public LogicalEntityBuilder<TEntity> Where<TValue>(
35
        Expression<Func<TEntity, TValue>> property,
36
        TValue parameterValue,
37
        FilterOperators filterOperator = FilterOperators.Equal)
38
    {
39
        return Where(property, parameterValue, null, filterOperator);
10✔
40
    }
41

42
    /// <inheritdoc />
43
    public LogicalEntityBuilder<TEntity> Where<TValue>(
44
        Expression<Func<TEntity, TValue>> property,
45
        TValue parameterValue,
46
        string tableAlias,
47
        FilterOperators whereOperator = FilterOperators.Equal)
48
    {
49
        var propertyAccessor = _typeAccessor.FindProperty(property);
10✔
50

51
        return Where(propertyAccessor.Column, parameterValue, tableAlias, whereOperator);
10✔
52
    }
53

54
    /// <inheritdoc />
55
    public LogicalEntityBuilder<TEntity> WhereIf<TValue>(
56
        Expression<Func<TEntity, TValue>> property,
57
        TValue parameterValue,
58
        FilterOperators filterOperator = FilterOperators.Equal,
59
        Func<string, TValue, bool> condition = null)
60
    {
61
        return WhereIf(property, parameterValue, null, filterOperator, condition);
×
62
    }
63

64
    /// <inheritdoc />
65
    public LogicalEntityBuilder<TEntity> WhereIf<TValue>(
66
        Expression<Func<TEntity, TValue>> property,
67
        TValue parameterValue,
68
        string tableAlias,
69
        FilterOperators filterOperator = FilterOperators.Equal,
70
        Func<string, TValue, bool> condition = null)
71
    {
72
        var propertyAccessor = _typeAccessor.FindProperty(property);
×
73

74
        return WhereIf(propertyAccessor.Column, parameterValue, tableAlias, filterOperator, condition);
×
75
    }
76

77
    /// <inheritdoc />
78
    public LogicalEntityBuilder<TEntity> WhereIn<TValue>(
79
        Expression<Func<TEntity, TValue>> property,
80
        IEnumerable<TValue> parameterValues,
81
        string tableAlias)
82
    {
83
        var propertyAccessor = _typeAccessor.FindProperty(property);
×
84

85
        return WhereIn(propertyAccessor?.Column, parameterValues, tableAlias);
×
86
    }
87

88
    /// <inheritdoc />
89
    public LogicalEntityBuilder<TEntity> WhereInIf<TValue>(
90
        Expression<Func<TEntity, TValue>> property,
91
        IEnumerable<TValue> parameterValues,
92
        Func<string, IEnumerable<TValue>, bool> condition = null)
93
    {
94
        var propertyAccessor = _typeAccessor.FindProperty(property);
×
95

96
        return WhereInIf(propertyAccessor?.Column, parameterValues, condition);
×
97
    }
98

99
    /// <inheritdoc />
100
    public LogicalEntityBuilder<TEntity> WhereInIf<TValue>(
101
        Expression<Func<TEntity, TValue>> property,
102
        IEnumerable<TValue> parameterValues,
103
        string tableAlias,
104
        Func<string, IEnumerable<TValue>, bool> condition = null)
105
    {
106
        var propertyAccessor = _typeAccessor.FindProperty(property);
×
107

108
        return WhereInIf(propertyAccessor?.Column, parameterValues, tableAlias, condition);
×
109
    }
110

111
    /// <inheritdoc />
112
    public LogicalEntityBuilder<TEntity> WhereOr(Action<LogicalEntityBuilder<TEntity>> builder)
113
    {
114
        var innerBuilder = new LogicalEntityBuilder<TEntity>(QueryGenerator, Parameters, LogicalOperators.Or);
1✔
115

116
        builder(innerBuilder);
1✔
117

118
        var statement = innerBuilder.BuildStatement();
1✔
119

120
        if (statement != null && statement.Statement.HasValue())
1✔
121
            WhereExpressions.Add(new WhereExpression(statement.Statement, IsRaw: true));
1✔
122

123
        return this;
1✔
124
    }
125

126
    /// <inheritdoc />
127
    public LogicalEntityBuilder<TEntity> WhereAnd(Action<LogicalEntityBuilder<TEntity>> builder)
128
    {
129
        var innerBuilder = new LogicalEntityBuilder<TEntity>(QueryGenerator, Parameters, LogicalOperators.And);
1✔
130

131
        builder(innerBuilder);
1✔
132

133
        var statement = innerBuilder.BuildStatement();
1✔
134

135
        if (statement != null && statement.Statement.HasValue())
1✔
136
            WhereExpressions.Add(new WhereExpression(statement.Statement, IsRaw: true));
1✔
137

138
        return this;
1✔
139
    }
140
}
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