DatabaseExtensionsNullIfWhiteSpace Method
This is used to convert strings to null values if they are empty or all whitespace
Namespace: EWSoftware.EntityFrameworkAssembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
public static string? NullIfWhiteSpace(
this string? value
)
<ExtensionAttribute>
Public Shared Function NullIfWhiteSpace (
value As String
) As String
public:
[ExtensionAttribute]
static String^ NullIfWhiteSpace(
String^ value
)
[<ExtensionAttribute>]
static member NullIfWhiteSpace :
value : string -> string
- value String
- The string value to check
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.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).
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.
using var dataContext = new MyDbContext();
dataContext.spOTWantedAddEdit(overtimeKey, entityKey,
dtpBeginDate.Value, dtpEndDate.Value, (byte)days,
(byte)shifts, txtWorksiteNote.Text.NullIfWhiteSpace(),
txtRequestNote.Text.NullIfWhiteSpace());