Class PivotValues
Translation-only marker for the typed PIVOT result projection. An instance of this type is
the second parameter of the projection passed to the typed SQL Server
Pivot overload: projection: (t, v) => ... v.Value<decimal?>("1") ....
public sealed class PivotValues
- Inheritance
-
PivotValues
- Inherited Members
- Extension Methods
Remarks
The marker carries no runtime state. It can also be instantiated and captured directly in an
ordinary Select over an existing PIVOT source. Only the query translator may bind a
Value<T>(string) call; executing an accessor outside a query expression throws
NotSupportedException.
The value string is a runtime identifier: it is not checked against the pivoted column at
compile time, so nothing guarantees the declared shape matches the data. A value that is absent from
the data still renders its result column but materializes as SQL NULL for every row (declare
the cell nullable when that is possible), and a malformed name or an incompatible explicit cell type
can fail during query preparation or materialization instead of being rejected up front.
This is the typed, statically declared projection: every pivot value is named in the projection. A truly dynamic PIVOT whose value list is known only at runtime stays outside this API and with the untyped TableAlias path.
Constructors
PivotValues()
Creates the marker. The constructor is public so a captured instance can be used in an
ordinary Select projection; the instance itself has no behaviour.
public PivotValues()
Methods
Value<T>(string)
References the PIVOT result column produced by columnName (one of
the PivotValue values), with an explicit CLR cell type.
public T Value<T>(string columnName)
Parameters
columnNamestringThe raw name of the pivot result column (one of the
PivotValuevalues). It is not SQL text: it is always safely quoted by the provider, regardless of the command'sQuoteIdentifiersoption, and is never stripped of brackets — manual pre-quoting is not supported, soValue<decimal?>("[1]")names the literal column[1](rendered[[1]]]on SQL Server), not the column1. The name is resolved at runtime, so an absent value or an incompatibleTis not rejected by the compiler: an absent value may yield SQLNULL, and an invalid name or type can fail during query preparation or materialization.
Returns
- T
The cell value, materialized as
T.
Type Parameters
TThe CLR type of the result column value.
Exceptions
- NotSupportedException
Always thrown: the accessor is translation-only and can only be used inside a query expression.