DatabaseExtensionsToNullableT(Object) Method

This is used to convert objects to null values if they are equal to null, DBNull.Value, or the default value for the given type.

Definition

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

Parameters

value  Object
The value to check

Type Parameters

T
The data type to use

Return Value

NullableT
If the value is set to null, DBNull.Value, or the default value for the 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 Object. 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 passed as a null rather than DBNull.Value or the type's default value.

Example

C#
using var dataContext = new MyDbContext())

// The BindableValue property returns an object so we specify the type
// for conversion.
dataContext.spUpdateStartDate(caseKey,
    dtpStartDate.BindableValue.ToNullable<DateTime>());

See Also