Database ExtensionsNull If White Space Method
This is used to convert strings to null values if they are empty or all whitespace
Definition
Namespace: EWSoftware.EntityFramework
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
If the value is null, empty, or contains nothing but whitespace this returns null. If it is not null, empty, or all whitespace it returns the passed value.
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
C#
public static string? NullIfWhiteSpace(
this string? value
)VB
<ExtensionAttribute>
Public Shared Function NullIfWhiteSpace (
value As String
) As StringC++
public:
[ExtensionAttribute]
static String^ NullIfWhiteSpace(
String^ value
)F#
[<ExtensionAttribute>]
static member NullIfWhiteSpace :
value : string -> string Parameters
- value String
- The string value to check
Return Value
StringIf the value is null, empty, or contains nothing but whitespace this returns null. If it is not null, empty, or all whitespace 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 String. 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 string values to database context methods when the value needs to
be stored as a null value rather than an empty or whitespace string.
Example
C#
using var dataContext = new MyDbContext();
dataContext.spOTWantedAddEdit(overtimeKey, entityKey,
dtpBeginDate.Value, dtpEndDate.Value, (byte)days,
(byte)shifts, txtWorksiteNote.Text.NullIfWhiteSpace(),
txtRequestNote.Text.NullIfWhiteSpace());