Class SqlBulkCopyValidationException

Namespace
Wolfgang.Etl.SqlBulkCopy
Assembly
Wolfgang.Etl.SqlBulkCopy.dll

Thrown by SqlBulkCopyLoader<TRecord> when an item (root or nested-collection child) fails DataAnnotation validation and the loader is configured to throw via Throw (the default).

public sealed class SqlBulkCopyValidationException : Exception, ISerializable
Inheritance
SqlBulkCopyValidationException
Implements
Inherited Members

Remarks

The loader always raises this exception through the SqlBulkCopyValidationException(object, IReadOnlyList<ValidationResult>) constructor, so Item and ValidationResults are populated for every instance the library itself throws. The conventional Exception constructors are also provided so the type is a well-behaved framework citizen (catch-rethrow with a custom message, wrapping an inner exception); instances created that way have a null Item and an empty ValidationResults.

Item is the failing instance — typed as object because the failure can come from either the root TRecord or a nested-collection child whose type is only known at load time. Callers can downcast when they know which side raised it.

ValidationResults holds the per-field failures from TryValidateObject(object, ValidationContext, ICollection<ValidationResult>, bool).

Constructors

SqlBulkCopyValidationException()

Initializes a new instance of the SqlBulkCopyValidationException class.

public SqlBulkCopyValidationException()

SqlBulkCopyValidationException(object, IReadOnlyList<ValidationResult>)

Initializes a new instance of the SqlBulkCopyValidationException class for a specific failing item and its validation errors. This is the constructor the loader uses.

public SqlBulkCopyValidationException(object item, IReadOnlyList<ValidationResult> validationResults)

Parameters

item object

The item that failed validation.

validationResults IReadOnlyList<ValidationResult>

The validation errors.

Exceptions

ArgumentNullException

Thrown when item or validationResults is null.

SqlBulkCopyValidationException(string)

Initializes a new instance of the SqlBulkCopyValidationException class with a specified error message.

public SqlBulkCopyValidationException(string message)

Parameters

message string

The message that describes the error.

SqlBulkCopyValidationException(string, Exception)

Initializes a new instance of the SqlBulkCopyValidationException class with a specified error message and a reference to the inner exception that caused it.

public SqlBulkCopyValidationException(string message, Exception innerException)

Parameters

message string

The message that describes the error.

innerException Exception

The exception that is the cause of this exception.

Properties

Item

Gets the item that failed validation, or null when the exception was created through one of the conventional Exception constructors.

public object? Item { get; }

Property Value

object

ValidationResults

Gets the validation errors produced by DataAnnotations. Empty when the exception was created through one of the conventional Exception constructors — the property initializer below supplies the empty default, and only the rich constructor overrides it.

public IReadOnlyList<ValidationResult> ValidationResults { get; }

Property Value

IReadOnlyList<ValidationResult>