• 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

76.92
/src/FluentCommand.SqlServer/Query/ChangeTableBuilder.cs
1
using FluentCommand.Extensions;
2
using FluentCommand.Query.Generators;
3
using FluentCommand.Reflection;
4

5
namespace FluentCommand.Query;
6

7
/// <summary>
8
/// Provides a builder for constructing SQL Server <c>CHANGETABLE (CHANGES ...)</c> queries for change tracking.
9
/// </summary>
10
public class ChangeTableBuilder : StatementBuilder<ChangeTableBuilder>
11
{
12
    private TableExpression? _fromTable;
13
    private QueryParameter? _parameter;
14

15
    /// <summary>
16
    /// Initializes a new instance of the <see cref="ChangeTableBuilder"/> class.
17
    /// </summary>
18
    /// <param name="queryGenerator">The query generator used to build SQL expressions.</param>
19
    /// <param name="parameters">The list of query parameters.</param>
20
    public ChangeTableBuilder(IQueryGenerator queryGenerator, List<QueryParameter> parameters) : base(queryGenerator, parameters)
2✔
21
    {
22
    }
2✔
23

24
    /// <summary>
25
    /// Specifies the source table for the <c>CHANGETABLE</c> query using the table name, schema, and optional alias.
26
    /// </summary>
27
    /// <param name="tableName">The name of the table to track changes for.</param>
28
    /// <param name="tableSchema">The schema of the table (optional).</param>
29
    /// <param name="tableAlias">The alias to use for the table in the query (optional).</param>
30
    /// <returns>The same <see cref="ChangeTableBuilder"/> instance for fluent chaining.</returns>
31
    public ChangeTableBuilder From(
32
        string tableName,
33
        string? tableSchema = null,
34
        string? tableAlias = null)
35
    {
36
        _fromTable = new TableExpression(tableName, tableSchema, tableAlias);
×
37

38
        return this;
×
39
    }
40

41
    /// <summary>
42
    /// Specifies the source table for the <c>CHANGETABLE</c> query using the entity type and optional alias.
43
    /// </summary>
44
    /// <typeparam name="TEntity">The entity type representing the table.</typeparam>
45
    /// <param name="tableAlias">The alias to use for the table in the query (optional).</param>
46
    /// <returns>The same <see cref="ChangeTableBuilder"/> instance for fluent chaining.</returns>
47
    public ChangeTableBuilder From<TEntity>(
48
        string? tableAlias = null)
49
    {
50
        var typeAccessor = TypeAccessor.GetAccessor<TEntity>();
4✔
51

52
        _fromTable = new TableExpression(typeAccessor.TableName, typeAccessor.TableSchema, tableAlias);
4✔
53

54
        return this;
4✔
55
    }
56

57
    /// <summary>
58
    /// Sets the last version value for the <c>CHANGETABLE</c> query, which is used to retrieve changes since the specified version.
59
    /// </summary>
60
    /// <param name="lastVersion">The last version number to use for change tracking.</param>
61
    /// <returns>The same <see cref="ChangeTableBuilder"/> instance for fluent chaining.</returns>
62
    public ChangeTableBuilder LastVersion(long lastVersion)
63
    {
64
        var name = NextParameter();
2✔
65
        _parameter = new QueryParameter(name, lastVersion, typeof(long));
2✔
66

67
        Parameters.Add(_parameter);
2✔
68

69
        return this;
2✔
70
    }
71

72
    /// <summary>
73
    /// Builds the <c>CHANGETABLE (CHANGES ...)</c> SQL statement using the specified table and version.
74
    /// </summary>
75
    /// <returns>
76
    /// A <see cref="QueryStatement"/> representing the constructed <c>CHANGETABLE</c> query and its parameters.
77
    /// </returns>
78
    public override QueryStatement? BuildStatement()
79
    {
80
        if (_fromTable is null)
2!
NEW
81
            throw new InvalidOperationException("The table source must be specified using From() before building the statement.");
×
82

83
        if (_parameter == null)
2!
84
            return new QueryStatement(QueryGenerator.TableExpression(_fromTable), Parameters);
×
85

86
        var table = QueryGenerator.TableExpression(new TableExpression(_fromTable.TableName, _fromTable.TableSchema));
2✔
87

88
        var statement = $"CHANGETABLE (CHANGES {table}, {_parameter.Name})";
2✔
89

90
        if (_fromTable.TableAlias.HasValue())
2✔
91
            statement += $" AS [{_fromTable.TableAlias}]";
2✔
92

93
        return new QueryStatement(statement, Parameters);
2✔
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