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

loresoft / FluentCommand / 26923300515

04 Jun 2026 01:03AM UTC coverage: 65.014% (+9.9%) from 55.157%
26923300515

push

github

pwelter34
Merge branch 'master' of https://github.com/loresoft/FluentCommand

1728 of 3450 branches covered (50.09%)

Branch coverage included in aggregate %.

5510 of 7683 relevant lines covered (71.72%)

297.61 hits per line

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

76.19
/src/FluentCommand/Query/QueryBuilderExtensions.cs
1
// Ignore Spelling: Sql
2

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

6
#pragma warning disable IDE0130 // Namespace does not match folder structure
7
namespace FluentCommand;
8

9
/// <summary>
10
/// Provides extension methods for building SQL queries using a <see cref="QueryBuilder"/> within a data session.
11
/// </summary>
12
public static class QueryBuilderExtensions
13
{
14
    /// <summary>
15
    /// Configures and sets the SQL command for the specified <see cref="IDataSession"/> using a fluent <see cref="QueryBuilder"/>.
16
    /// </summary>
17
    /// <param name="dataSession">The data session used to execute the query.</param>
18
    /// <param name="builder">
19
    /// An action that configures the <see cref="QueryBuilder"/> to build the desired SQL statement and parameters.
20
    /// </param>
21
    /// <returns>
22
    /// An <see cref="IDataCommand"/> representing the configured SQL command, ready for execution or further configuration.
23
    /// </returns>
24
    /// <remarks>
25
    /// This method creates a new <see cref="QueryBuilder"/> using the session's <see cref="IQueryGenerator"/> and a fresh parameter list.
26
    /// The <paramref name="builder"/> action is invoked to configure the query. The resulting SQL and parameters are then applied to the session's data command.
27
    /// </remarks>
28
    public static IDataCommand Sql(this IDataSession dataSession, Action<QueryBuilder> builder)
29
    {
30
        var queryParameters = new List<QueryParameter>();
88✔
31
        var queryBuilder = new QueryBuilder(dataSession.QueryGenerator, queryParameters)
88✔
32
            .UseJsonSerializerOptions(dataSession.JsonSerializerOptions);
88✔
33

34
        builder(queryBuilder);
88✔
35

36
        var statement = queryBuilder.BuildStatement();
88✔
37

38
        var dataCommand = dataSession.Sql(statement?.Statement ?? string.Empty);
88!
39

40
        if (statement?.Parameters == null)
88!
41
            return dataCommand;
×
42

43
        foreach (var parameter in statement.Parameters)
940✔
44
            dataCommand.Parameter(parameter.Name, parameter.Value, parameter.Type);
382✔
45

46
        return dataCommand;
88✔
47
    }
48
}
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