I am using an ADO.NET Entity-Framework ObjectContext to access my data store.
I want the if values are set with empty strings, they should automatically become null.
Rather than complicating things by overriding the ObjectContext I use string extension methods to convert values for database storage
public static class StringExtensions
{
public static string EmptyStringToNull(this string s)
{
return string.IsNullOrWhiteSpace(s) ? null : s;
}
public static object EmptyStringToDBNull(this string s)
{
if (string.IsNullOrWhiteSpace(s))
return DBNull.Value;
else
return s;
}
}