I have this data access method that return the availability of a lot in our ERP:
public JDEItemLotAvailability GetLotAvailabilityF41021(string _lot)
{
JDEItemLotAvailability _retValue = new JDEItemLotAvailability();
_retValue.Lot = _lot;
using (OleDbConnection con = new OleDbConnection(_ERPConfig.ConnectionString))
{
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText =
"select max(lilotn) lilotn,max(trim(limcu)) limcu,max(lilocn) lilocn," +
"max(lipqoh/100) lipqoh,max(liitm) liitm,max(imlitm) imlitm," +
"max(concat(imdsc1,imdsc2)) as imdsc,max(imuom1 ) imuom1 " +
"from "+ _ERPConfig .AS400Library +".f41021" + " left outer join proddta.f4101 on liitm=imitm " +
"where lilotn = ?";
cmd.Parameters.AddWithValue("@lilotn", _lot);
cmd.Connection = con;
con.Open();
OleDbDataReader rdr = cmd.ExecuteReader();
if (rdr.HasRows)
{
rdr.Read();
if (rdr["lilotn"] != DBNull.Value)
{
_retValue.Code = rdr.GetString(rdr.GetOrdinal("imlitm"));
_retValue.ShortCode = (int)rdr.GetDecimal(rdr.GetOrdinal("liitm"));
_retValue.Description = rdr.GetString(rdr.GetOrdinal("imdsc"));
_retValue.PrimaryUnitCode = rdr.GetString(rdr.GetOrdinal("imuom1"));
_retValue.AvailableQuantity = (int)rdr.GetDecimal(rdr.GetOrdinal("lipqoh"));
_retValue.BranchPlant = rdr.GetString(rdr.GetOrdinal("limcu"));
_retValue.Location = rdr.GetString(rdr.GetOrdinal("lilocn"));
}
}
}
return _retValue;
}
In case the method doesnt have rows the lot that will be returned has only one data field filled. Thats the way i am checking on above bussiness layer if it was successfull or not.
I dont like it. Someone mentioned tuple as a solution.
I guess i will have my method return a tuple<MyObject, bool>
for example ?
Added info: I would like to be able to return also an answer to "why the object is null?". I am thinking of returning a tuple of object and an ENUM specifying the reason.
UPDATE:
I think i am gonna go this route:
Return a NULL object reference from data access method and have the BLL method return a tuple<Myobject,ENUMreason>