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.
Namespace: EWSoftware.EntityFrameworkAssembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
public static T? ToNullable<T>(
this Object? value
)
where T : struct, new()
<ExtensionAttribute>
Public Shared Function ToNullable(Of T As {Structure, New}) (
value As Object
) As T?
public:
[ExtensionAttribute]
generic<typename T>
where T : value class, gcnew()
static Nullable<T> ToNullable(
Object^ value
)
[<ExtensionAttribute>]
static member ToNullable :
value : Object -> Nullable<'T> when 'T : struct, new()
- value Object
- The value to check
- T
- The data type to use
NullableTIf 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.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).
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.
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>());