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