DatabaseExtensionsNullIfWhiteSpace 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
public static string? NullIfWhiteSpace(
	this string? value
)

Parameters

value  String
The string value to check

Return Value

String
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.

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());

See Also