I need to use Convert.DBNull for every single null value while adding parameters of sqlCommands. It's tedious because I have a lot of sql commands. So it would be lot easier if there is any way like setting this Object(Convert.DBNull)as parameter whenever it gets a null value as parameter.
Example: I have a code like this:
cmd.Parameters.AddWithValue("@MasterLastModifiedBy", Master.LastModifiedBy);
As variables like Master.LastModifiedBy might be null sometimes, therefore I have to reformat that into this:
cmd.Parameters.AddWithValue("@MasterLastModifiedBy", Master.LastModifiedBy?? Convert.DBNull);
I don't want to do this reformatting in all parameters. So, what else can I do to resolve this problem?
AddWithValueWithNiceNullHandling(or whatever name you want) which does the??for you. This will thus allow you to still passnullwhen you explicit want to, but call your new method to useDBNull.Valueinstead.