• 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

40.58
/src/FluentCommand/Query/DeleteEntityBuilder.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

10
/// <summary>
11
/// Delete query statement builder
12
/// </summary>
13
/// <typeparam name="TEntity">The type of the entity.</typeparam>
14
public class DeleteEntityBuilder<TEntity>
15
    : DeleteBuilder<DeleteEntityBuilder<TEntity>>, IWhereEntityBuilder<TEntity, DeleteEntityBuilder<TEntity>>
16
    where TEntity : class
17
{
18
    private static readonly TypeAccessor _typeAccessor = TypeAccessor.GetAccessor<TEntity>();
5✔
19

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

34

35
    /// <summary>
36
    /// Add an output clause for the specified property.
37
    /// </summary>
38
    /// <typeparam name="TValue">The type of the value.</typeparam>
39
    /// <param name="property">The property.</param>
40
    /// <param name="tableAlias">The table alias.</param>
41
    /// <param name="columnAlias">The column alias.</param>
42
    /// <returns>
43
    /// The same builder so that multiple calls can be chained.
44
    /// </returns>
45
    public DeleteEntityBuilder<TEntity> Output<TValue>(
46
        Expression<Func<TEntity, TValue>> property,
47
        string tableAlias = "DELETED",
48
        string columnAlias = null)
49
    {
50
        var propertyAccessor = _typeAccessor.FindProperty(property);
6✔
51
        return Output(propertyAccessor.Column, tableAlias, columnAlias);
6✔
52
    }
53

54
    /// <summary>
55
    /// Conditionally add an output clause for the specified property.
56
    /// </summary>
57
    /// <typeparam name="TValue">The type of the value.</typeparam>
58
    /// <param name="property">The property.</param>
59
    /// <param name="tableAlias">The table alias.</param>
60
    /// <param name="columnAlias">The column alias.</param>
61
    /// <param name="condition">The condition.</param>
62
    /// <returns>
63
    /// The same builder so that multiple calls can be chained.
64
    /// </returns>
65
    public DeleteEntityBuilder<TEntity> OutputIf<TValue>(
66
        Expression<Func<TEntity, TValue>> property,
67
        string tableAlias = "DELETED",
68
        string columnAlias = null,
69
        Func<string, bool> condition = null)
70
    {
71
        var propertyAccessor = _typeAccessor.FindProperty(property);
×
72
        return OutputIf(propertyAccessor.Column, tableAlias, columnAlias, condition);
×
73
    }
74

75
    /// <inheritdoc />
76
    public override DeleteEntityBuilder<TEntity> From(
77
        string tableName = null,
78
        string tableSchema = null,
79
        string tableAlias = null)
80
    {
81
        return base.From(
1✔
82
            tableName ?? _typeAccessor.TableName,
1✔
83
            tableSchema ?? _typeAccessor.TableSchema,
1✔
84
            tableAlias);
1✔
85
    }
86

87
    /// <summary>
88
    /// Add a join clause using the specified builder action
89
    /// </summary>
90
    /// <typeparam name="TRight">The right join entity</typeparam>
91
    /// <param name="builder">The join builder.</param>
92
    /// <returns>
93
    /// The same builder so that multiple calls can be chained.
94
    /// </returns>
95
    public DeleteEntityBuilder<TEntity> Join<TRight>(Action<JoinEntityBuilder<TEntity, TRight>> builder)
96
        where TRight : class
97
    {
98
        var innerBuilder = new JoinEntityBuilder<TEntity, TRight>(QueryGenerator, Parameters);
1✔
99
        builder(innerBuilder);
1✔
100

101
        JoinExpressions.Add(innerBuilder.BuildExpression());
1✔
102

103
        return this;
1✔
104
    }
105

106
    /// <summary>
107
    /// Add a join clause using the specified builder action
108
    /// </summary>
109
    /// <typeparam name="TLeft">The left join entity</typeparam>
110
    /// <typeparam name="TRight">The right join entity</typeparam>
111
    /// <param name="builder">The join builder.</param>
112
    /// <returns>
113
    /// The same builder so that multiple calls can be chained.
114
    /// </returns>
115
    public DeleteEntityBuilder<TEntity> Join<TLeft, TRight>(Action<JoinEntityBuilder<TLeft, TRight>> builder)
116
        where TLeft : class
117
        where TRight : class
118
    {
119
        var innerBuilder = new JoinEntityBuilder<TLeft, TRight>(QueryGenerator, Parameters);
×
120
        builder(innerBuilder);
×
121

122
        JoinExpressions.Add(innerBuilder.BuildExpression());
×
123

124
        return this;
×
125
    }
126

127

128
    /// <inheritdoc />
129
    public DeleteEntityBuilder<TEntity> Where<TValue>(
130
        Expression<Func<TEntity, TValue>> property,
131
        TValue parameterValue,
132
        FilterOperators filterOperator = FilterOperators.Equal)
133
    {
134
        return Where<TValue>(property, parameterValue, null, filterOperator);
5✔
135
    }
136

137
    /// <inheritdoc />
138
    public DeleteEntityBuilder<TEntity> Where<TValue>(
139
        Expression<Func<TEntity, TValue>> property,
140
        TValue parameterValue,
141
        string tableAlias,
142
        FilterOperators filterOperator = FilterOperators.Equal)
143
    {
144
        var propertyAccessor = _typeAccessor.FindProperty(property);
5✔
145

146
        return Where(propertyAccessor.Column, parameterValue, tableAlias, filterOperator);
5✔
147
    }
148

149
    /// <summary>
150
    /// Create a where clause with the specified property, value, operator and table alias
151
    /// </summary>
152
    /// <typeparam name="TModel">The type of the model</typeparam>
153
    /// <typeparam name="TValue">The type of the value.</typeparam>
154
    /// <param name="property">The property.</param>
155
    /// <param name="parameterValue">The parameter value.</param>
156
    /// <param name="tableAlias">The table alias.</param>
157
    /// <param name="filterOperator">The filter operator.</param>
158
    /// <returns>
159
    /// The same builder so that multiple calls can be chained.
160
    /// </returns>
161
    public DeleteEntityBuilder<TEntity> Where<TModel, TValue>(
162
        Expression<Func<TModel, TValue>> property,
163
        TValue parameterValue,
164
        string tableAlias,
165
        FilterOperators filterOperator = FilterOperators.Equal)
166
    {
167
        var typeAccessor = TypeAccessor.GetAccessor<TModel>();
1✔
168
        var propertyAccessor = typeAccessor.FindProperty(property);
1✔
169

170
        return Where(propertyAccessor.Column, parameterValue, tableAlias, filterOperator);
1✔
171
    }
172

173
    /// <inheritdoc />
174
    public DeleteEntityBuilder<TEntity> WhereIf<TValue>(
175
        Expression<Func<TEntity, TValue>> property,
176
        TValue parameterValue,
177
        FilterOperators filterOperator = FilterOperators.Equal,
178
        Func<string, TValue, bool> condition = null)
179
    {
180
        return WhereIf(property, parameterValue, null, filterOperator, condition);
×
181
    }
182

183
    /// <inheritdoc />
184
    public DeleteEntityBuilder<TEntity> WhereIf<TValue>(
185
        Expression<Func<TEntity, TValue>> property,
186
        TValue parameterValue,
187
        string tableAlias,
188
        FilterOperators filterOperator = FilterOperators.Equal,
189
        Func<string, TValue, bool> condition = null)
190
    {
191
        var propertyAccessor = _typeAccessor.FindProperty(property);
×
192

193
        return WhereIf(propertyAccessor.Column, parameterValue, tableAlias, filterOperator, condition);
×
194
    }
195

196
    /// <inheritdoc />
197
    public DeleteEntityBuilder<TEntity> WhereIn<TValue>(
198
        Expression<Func<TEntity, TValue>> property,
199
        IEnumerable<TValue> parameterValues,
200
        string tableAlias)
201
    {
202
        var propertyAccessor = _typeAccessor.FindProperty(property);
×
203

204
        return WhereIn(propertyAccessor?.Column, parameterValues, tableAlias);
×
205
    }
206

207
    /// <inheritdoc />
208
    public DeleteEntityBuilder<TEntity> WhereInIf<TValue>(
209
        Expression<Func<TEntity, TValue>> property,
210
        IEnumerable<TValue> parameterValues,
211
        Func<string, IEnumerable<TValue>, bool> condition = null)
212
    {
213
        var propertyAccessor = _typeAccessor.FindProperty(property);
×
214

215
        return WhereInIf(propertyAccessor?.Column, parameterValues, condition);
×
216
    }
217

218
    /// <inheritdoc />
219
    public DeleteEntityBuilder<TEntity> WhereInIf<TValue>(
220
        Expression<Func<TEntity, TValue>> property,
221
        IEnumerable<TValue> parameterValues,
222
        string tableAlias,
223
        Func<string, IEnumerable<TValue>, bool> condition = null)
224
    {
225
        var propertyAccessor = _typeAccessor.FindProperty(property);
×
226

227
        return WhereInIf(propertyAccessor?.Column, parameterValues, tableAlias, condition);
×
228
    }
229

230
    /// <inheritdoc />
231
    public DeleteEntityBuilder<TEntity> WhereOr(Action<LogicalEntityBuilder<TEntity>> builder)
232
    {
233
        var innerBuilder = new LogicalEntityBuilder<TEntity>(QueryGenerator, Parameters, LogicalOperators.Or);
×
234

235
        builder(innerBuilder);
×
236

237
        var statement = innerBuilder.BuildStatement();
×
238

239
        if (statement != null && statement.Statement.HasValue())
×
240
            WhereExpressions.Add(new WhereExpression(statement.Statement, IsRaw: true));
×
241

242
        return this;
×
243
    }
244

245
    /// <inheritdoc />
246
    public DeleteEntityBuilder<TEntity> WhereAnd(Action<LogicalEntityBuilder<TEntity>> builder)
247
    {
248
        var innerBuilder = new LogicalEntityBuilder<TEntity>(QueryGenerator, Parameters, LogicalOperators.And);
×
249

250
        builder(innerBuilder);
×
251

252
        var statement = innerBuilder.BuildStatement();
×
253

254
        if (statement != null && statement.Statement.HasValue())
×
255
            WhereExpressions.Add(new WhereExpression(statement.Statement, IsRaw: true));
×
256

257
        return this;
×
258
    }
259

260

261
    /// <inheritdoc />
262
    public override QueryStatement BuildStatement()
263
    {
264
        // add table and schema from attribute if not set
265
        if (TableExpression == null)
6✔
266
            Table(_typeAccessor.TableName, _typeAccessor.TableSchema);
6✔
267

268
        return base.BuildStatement();
6✔
269
    }
270
}
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