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).

Definition

Namespace: EWSoftware.EntityFramework
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
public static T? ToNullable<T>(
	this T value
)
where T : struct, new()

Parameters

value  T
The value to check

Type Parameters

T
The data type to use

Return Value

NullableT
If the value is set to the default value for its type, this returns null. If not, it returns the passed value.

Usage Note

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).

Remarks

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.

Example

C#
using var dataContext = new MyDbContext();

dataContext.spUpdateStartDate(caseKey, startDate.ToNullable());

See Also