Database ExtensionsTo NullableT(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
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.
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
C#
public static T? ToNullable<T>(
this Object? value
)
where T : struct, new()
VB
<ExtensionAttribute>
Public Shared Function ToNullable(Of T As {Structure, New}) (
value As Object
) As T?C++
public:
[ExtensionAttribute]
generic<typename T>
where T : value class, gcnew()
static Nullable<T> ToNullable(
Object^ value
)F#
[<ExtensionAttribute>]
static member ToNullable :
value : Object -> Nullable<'T> when 'T : struct, new()Parameters
- value Object
- The value to check
Type Parameters
- T
- The data type to use
Return Value
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.
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>());