Class CsvStreamOptions
Options controlling the dialect of the CSV written by
QueryCommandExtensions.WriteCsv/WriteCsvAsync (and the
EntityBuilder<TEntity> overloads).
public sealed class CsvStreamOptions
- Inheritance
-
CsvStreamOptions
- Inherited Members
- Extension Methods
Remarks
The output is always UTF-8 without a byte-order mark, uses RFC 4180 escaping and CRLF row terminators, and formats values with the invariant culture.
Fields
DefaultNullMarker
The NULL marker written by default; two characters, backslash and N.
public const string DefaultNullMarker = "\\N"
Field Value
Properties
Delimiter
Gets or sets the field delimiter. Defaults to ','.
public char Delimiter { get; set; }
Property Value
ExcelMode
Gets or sets a value indicating whether the Excel formula-injection guard is enabled. Defaults to false.
public bool ExcelMode { get; set; }
Property Value
Remarks
When enabled, a field whose text begins with =, +, - or @ is prefixed with an
apostrophe (') so spreadsheet applications treat it as text rather than a formula. The guard runs
after ValueTransform and before RFC 4180 escaping, so the apostrophe is part of the escaped
value. It applies to the formatted text of every column, including negative numeric values.
IncludeHeader
Gets or sets a value indicating whether a header row is written before the data rows. Defaults to true.
public bool IncludeHeader { get; set; }
Property Value
NullMarker
Gets or sets the literal text written for a SQL NULL. Defaults to DefaultNullMarker (\N).
public string NullMarker { get; set; }
Property Value
Remarks
The contract distinguishes NULL from an empty field: NULL is always written as this marker, while a
non-NULL empty string (or an empty byte[]) is written as an empty field. Because the marker is a
literal value too, a non-NULL value whose formatted text equals the marker exactly is quoted
("\N") so a reader never mistakes it for NULL. The marker must be non-empty and must not contain
the delimiter, a double quote, CR or LF; these combinations are rejected before any output.
ValueTransform
Gets or sets an optional per-value transform, or null (the default) to keep the box-free typed formatting path.
public Func<object?, string?>? ValueTransform { get; set; }
Property Value
Remarks
The transform receives every non-NULL value (boxed) and returns the text that replaces the default formatting, or null to write the NULL marker. It runs before the Excel guard and before CSV escaping, so a transform may itself introduce a formula prefix that the guard then neutralises. A SQL NULL never invokes the transform; it is always written as NullMarker.