Class DataStatementOptions
Configuration options for DataStatement.
public class DataStatementOptions : IValidatableParameterObject, IParameterObject
- Inheritance
-
DataStatementOptions
- Implements
Examples
DataStatementOptions provides configuration for DataStatement instances including command type, timeout, and parameters. This example creates a text command option with a 30-second timeout and prints its CommandType and timeout values, then creates a stored procedure option with a 5-minute timeout and an empty IDataParameter array. After configuration, ValidateOptions() is called to confirm the stored procedure settings are valid. Console output displays the command type, timeout in seconds, and validation status.
using System;
using System.Data;
using Cuemon.Data;
namespace MyApp.Data
{
public class DataStatementOptionsExample
{
public void Demonstrate()
{
// Create options for a text command with default timeout (90 seconds)
var options = new DataStatementOptions
{
Type = CommandType.Text,
Timeout = TimeSpan.FromSeconds(30)
};
Console.WriteLine($"Command type: {options.Type}");
Console.WriteLine($"Timeout: {options.Timeout.TotalSeconds} seconds");
Console.WriteLine($"Default timeout: {DataStatementOptions.DefaultTimeout.TotalSeconds} seconds");
// Configure for a stored procedure
var spOptions = new DataStatementOptions
{
Type = CommandType.StoredProcedure,
Timeout = TimeSpan.FromMinutes(5),
Parameters = Array.Empty<IDataParameter>()
};
// Validate that parameters is not null
spOptions.ValidateOptions();
Console.WriteLine("Stored procedure options are valid.");
}}
}
Constructors
DataStatementOptions()
Initializes a new instance of the DataStatementOptions class.
public DataStatementOptions()
Properties
DefaultTimeout
Gets or sets the default wait time before terminating the attempt to execute a command and generating an error.
public static TimeSpan DefaultTimeout { get; set; }
Property Value
Parameters
Gets or sets the parameters to use in the command.
public IDataParameter[] Parameters { get; set; }
Property Value
- IDataParameter[]
The parameters to use in the command.
Timeout
Gets or sets the wait time before terminating the attempt to execute a command and generating an error.
public TimeSpan Timeout { get; set; }
Property Value
- TimeSpan
The timespan to wait for the command to execute. Default value is 1 minute and 30 seconds.
Type
Gets the command type value to execute.
public CommandType Type { get; set; }
Property Value
- CommandType
The command type value to execute. Default type value is Text.
Methods
ValidateOptions()
Determines whether the public read-write properties of this instance are in a valid state.
public void ValidateOptions()
Remarks
This method is expected to throw exceptions when one or more conditions fails to be in a valid state.