Class QueryFormatExtensions
- Namespace
- Cuemon.Extensions.Data
- Assembly
- Cuemon.Extensions.Data.dll
Extension methods for the QueryFormat enum.
public static class QueryFormatExtensions
- Inheritance
-
QueryFormatExtensions
Examples
The following example demonstrates generating query fragments for SQL IN clauses using the Embed(QueryFormat, IEnumerable<string>, bool) 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
Embed(QueryFormat, IEnumerable<int>, bool)
Embeds the specified int sequence within the desired query fragment format.
public static string Embed(this QueryFormat format, IEnumerable<int> values, bool distinct = false)
Parameters
formatQueryFormatThe QueryFormat to extend.
valuesIEnumerable<int>The values to be generated in the specified format for the query fragment.
distinctboolif set to
true,valueswill be filtered for doublets.
Returns
- string
A query fragment in the desired format.
Embed(QueryFormat, IEnumerable<long>, bool)
Embeds the specified long sequence within the desired query fragment format.
public static string Embed(this QueryFormat format, IEnumerable<long> values, bool distinct = false)
Parameters
formatQueryFormatThe QueryFormat to extend.
valuesIEnumerable<long>The values to be generated in the specified format for the query fragment.
distinctboolif set to
true,valueswill be filtered for doublets.
Returns
- string
A query fragment in the desired format.
Embed(QueryFormat, IEnumerable<string>, bool)
Embeds the specified string sequence within the desired query fragment format.
public static string Embed(this QueryFormat format, IEnumerable<string> values, bool distinct = false)
Parameters
formatQueryFormatThe QueryFormat to extend.
valuesIEnumerable<string>The values to be generated in the specified format for the query fragment.
distinctboolif set to
true,valueswill be filtered for doublets.
Returns
- string
A query fragment in the desired format.
Exceptions
- ArgumentNullException
valuescannot be null.- ArgumentException
valuescontains no elements.