• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

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

0.0
/src/FluentCommand/Query/WhereEntityBuilder.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
/// Where clause builder
11
/// </summary>
12
/// <typeparam name="TEntity">The type of the entity.</typeparam>
13
public class WhereEntityBuilder<TEntity>
14
    : WhereBuilder<WhereEntityBuilder<TEntity>>, IWhereEntityBuilder<TEntity, WhereEntityBuilder<TEntity>>
15
    where TEntity : class
16
{
17
    private static readonly TypeAccessor _typeAccessor = TypeAccessor.GetAccessor<TEntity>();
×
18

19
    /// <summary>
20
    /// Initializes a new instance of the <see cref="WhereEntityBuilder{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 logical operator.</param>
25
    public WhereEntityBuilder(
26
        IQueryGenerator queryGenerator,
27
        List<QueryParameter> parameters,
28
        LogicalOperators logicalOperator = LogicalOperators.And)
29
        : base(queryGenerator, parameters, logicalOperator)
×
30
    {
31
    }
×
32

33

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

43
    /// <inheritdoc />
44
    public WhereEntityBuilder<TEntity> Where<TValue>(
45
        Expression<Func<TEntity, TValue>> property,
46
        TValue parameterValue,
47
        string tableAlias,
48
        FilterOperators filterOperator = FilterOperators.Equal)
49
    {
50
        var propertyAccessor = _typeAccessor.FindProperty(property);
×
51

52
        return Where(propertyAccessor?.Column, parameterValue, tableAlias, filterOperator);
×
53
    }
54

55
    /// <inheritdoc />
56
    public WhereEntityBuilder<TEntity> WhereIn<TValue>(
57
        Expression<Func<TEntity, TValue>> property,
58
        IEnumerable<TValue> parameterValues,
59
        string tableAlias)
60
    {
61
        var propertyAccessor = _typeAccessor.FindProperty(property);
×
62

63
        return WhereIn(propertyAccessor?.Column, parameterValues, tableAlias);
×
64
    }
65

66
    /// <inheritdoc />
67
    public WhereEntityBuilder<TEntity> WhereInIf<TValue>(
68
        Expression<Func<TEntity, TValue>> property,
69
        IEnumerable<TValue> parameterValues,
70
        Func<string, IEnumerable<TValue>, bool> condition = null)
71
    {
72
        var propertyAccessor = _typeAccessor.FindProperty(property);
×
73

74
        return WhereInIf(propertyAccessor?.Column, parameterValues, condition);
×
75
    }
76

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

86
        return WhereInIf(propertyAccessor?.Column, parameterValues, tableAlias, condition);
×
87
    }
88

89
    /// <inheritdoc />
90
    public WhereEntityBuilder<TEntity> WhereIf<TValue>(
91
        Expression<Func<TEntity, TValue>> property,
92
        TValue parameterValue,
93
        FilterOperators filterOperator = FilterOperators.Equal,
94
        Func<string, TValue, bool> condition = null)
95
    {
96
        return WhereIf(property, parameterValue, null, filterOperator, condition);
×
97
    }
98

99
    /// <inheritdoc />
100
    public WhereEntityBuilder<TEntity> WhereIf<TValue>(
101
        Expression<Func<TEntity, TValue>> property,
102
        TValue parameterValue,
103
        string tableAlias,
104
        FilterOperators filterOperator = FilterOperators.Equal,
105
        Func<string, TValue, bool> condition = null)
106
    {
107
        var propertyAccessor = _typeAccessor.FindProperty(property);
×
108

109
        return WhereIf(propertyAccessor?.Column, parameterValue, tableAlias, filterOperator, condition);
×
110
    }
111

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

117
        builder(innerBuilder);
×
118

119
        var statement = innerBuilder.BuildStatement();
×
120

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

124
        return this;
×
125
    }
126

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

132
        builder(innerBuilder);
×
133

134
        var statement = innerBuilder.BuildStatement();
×
135

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

139
        return this;
×
140
    }
141

142
    /// <inheritdoc />
143
    public override QueryStatement BuildStatement()
144
    {
145
        if (WhereExpressions == null || WhereExpressions.Count == 0)
×
146
            return null;
×
147

148
        var statement = QueryGenerator.BuildWhere(WhereExpressions);
×
149

150
        return new QueryStatement(statement, Parameters);
×
151
    }
152
}
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