Table of Contents

QueryFormatExtensions Class

Definition

Namespace
Cuemon.Extensions.Data
Assemblies
Cuemon.Extensions.Data.dll
Source
src/Cuemon.Extensions.Data/QueryFormatExtensions.cs

Extension methods for the QueryFormat enum.

public static class QueryFormatExtensions
Inheritance
object
QueryFormatExtensions

Examples

The following example demonstrates generating query fragments for SQL IN clauses using the Embed extension method.

using System;
using System.Collections.Generic;
using Cuemon.Data;
using Cuemon.Extensions.Data;

namespace MyApp.Examples;

public class QueryFormatExtensionsExample
{
    public static void Main()
    {
        // Embed string values in a delimited format: value, value, value
        var productIds = new[] { "ALFKI", "BONAP", "FRANS" };
        string delimited = QueryFormat.Delimited.Embed(productIds);
        Console.WriteLine(delimited); // Output: "ALFKI", "BONAP", "FRANS"

        // Embed string values with single quotes: 'value', 'value', 'value'
        string delimitedString = QueryFormat.DelimitedString.Embed(productIds);
        Console.WriteLine(delimitedString); // Output: 'ALFKI', 'BONAP', 'FRANS'

        // Embed integer values
        var ids = new[] { 1, 2, 3, 4, 5 };
        string intEmbedded = QueryFormat.Delimited.Embed(ids);
        Console.WriteLine(intEmbedded); // Output: 1, 2, 3, 4, 5

        // Embed with distinct filtering to remove duplicates
        var withDuplicates = new[] { "apple", "banana", "apple", "cherry" };
        string distinctFragment = QueryFormat.DelimitedString.Embed(withDuplicates, distinct: true);
        Console.WriteLine(distinctFragment); // Output: 'apple', 'banana', 'cherry'

}
}

Methods

Name Description
Embed(QueryFormat, IEnumerable<int>, bool)

Embeds the specified int sequence within the desired query fragment format.

Embed(QueryFormat, IEnumerable<long>, bool)

Embeds the specified long sequence within the desired query fragment format.

Embed(QueryFormat, IEnumerable<string>, bool)

Embeds the specified string sequence within the desired query fragment format.