DatabaseExtensionsToNullableT(T) Method
This is used to convert value types to null values if they are set to their default value for the
type (i.e. zero for integers, DateTime.MinValue for date/times, etc).
Namespace: EWSoftware.EntityFrameworkAssembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
public static T? ToNullable<T>(
this T value
)
where T : struct, new()
<ExtensionAttribute>
Public Shared Function ToNullable(Of T As {Structure, New}) (
value As T
) As T?
public:
[ExtensionAttribute]
generic<typename T>
where T : value class, gcnew()
static Nullable<T> ToNullable(
T value
)
[<ExtensionAttribute>]
static member ToNullable :
value : 'T -> Nullable<'T> when 'T : struct, new()
- value T
- The value to check
- T
- The data type to use
NullableTIf the value is set to the default value for its type, this returns
null. If not, it
returns the passed value.In Visual Basic and C#, you can call this method as an instance method on any object of type
T. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
This is useful for passing values to database context methods when the parameters needs to
be stored as a null value rather than a literal value if it is set to the default.
using var dataContext = new MyDbContext();
dataContext.spUpdateStartDate(caseKey, startDate.ToNullable());