public static class DbUtils
{
public static object ToDbParameter<T>(this T? value) where T : struct
{
object dbValue = value;
if (dbValue == null)
{
dbValue = DBNull.Value;
}
return dbValue;
}
public static object ToDbParameter(this object value) {
object dbValue = value;
if (dbValue == null)
{
dbValue = DBNull.Value;
}
return dbValue;
}
}
command.Parameters.Add("FirstName", SqlDbType.VarChar, 256).Value = person.FirstName;
command.Parameters.Add("LastName", SqlDbType.VarChar, 256).Value = person.LastName.ToDbParameter();
command.Parameters.Add("DateOfBirth", SqlDbType.SmallDateTime).Value = person.DateOfBirth.ToDbParameter();
command.Parameters.Add("GenderId", SqlDbType.Int).Value = person.GenderId.ToDbParameter();