Does the Enterprise Library Data Access Block provider support c# nullable types as parameters to pl/pgsql functions ? For example, can I add an input parameter of type int? vs. just int. Same question for OUT params in PL/PGSQL.
thanks.
c# nullable types as parameters
Concretely, can the _retval and _hashkey parameters below be passed in as c# int? type, and have null values, assuming the db columns are nullable.
Code: Select all
public bool add(string config, string _subscriptionid, string _topicid, string _notifyaddress, System.DateTime _expiration, string _ownerdata, string _notifychannel, bool _hasexpiration)
{
try
{
string hashSource = "eventpubsub:topic:" + _topicid.ToString();
Database db = CreateHashedDatabase(config, hashSource);
string sqlCommand = "subscription_add";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
db.AddInParameter(dbCommand, "_hashkey", DbType.Int32, _hashkey);
db.AddInParameter(dbCommand, "_subscriptionid", DbType.String, _subscriptionid);
db.AddInParameter(dbCommand, "_topicid", DbType.String, _topicid);
db.AddInParameter(dbCommand, "_notifyaddress", DbType.String, _notifyaddress);
db.AddInParameter(dbCommand, "_expiration", DbType.DateTime, _expiration);
db.AddInParameter(dbCommand, "_ownerdata", DbType.String, _ownerdata);
db.AddInParameter(dbCommand, "_notifychannel", DbType.String, _notifychannel);
db.AddInParameter(dbCommand, "_hasexpiration", DbType.Boolean, _hasexpiration);
db.AddOutParameter(dbCommand, "_retval", DbType.Boolean, 1);
db.ExecuteNonQuery(dbCommand);
return (bool)db.GetParameterValue(dbCommand, "_retval");
}
catch (Exception ex)
{
Logger.Error(11000, ex.ToString());
throw(ex);
}
}
Yes, they can be. You would have to add a function to unwrap nullable type. Take a look at the following passage:
Code: Select all
public static object UnwrapNullable(Nullable val) {
if (!val.HasValue)
return null;
return val.value;
}
...
int? _hashkey;
...
db.AddInParameter(dbCommand, "_hashkey", DbType.Int32, UnwrapNullable(_hashkey));