I am working on the optimization of server side application, and i want to pass in optional parameters to a method and make where clause in function of those parameters.
Method 1:
public static Lane GetLane(string laneCode)
{
AppContext.TraceLogger.VerboseIf(MethodBase.GetCurrentMethod().Name, traceSwitch);
try
{
using (GFC_Entities connexionEF = new GFC_Entities())
{
Lane lane = connexionEF.Lanes.Where(ln => ln.ShortDescription.Trim() == laneCode.Trim()).FirstOrDefault();
CacheManager.AddToCache(cache_key, lane);
return lane;
}
}
catch (EntityException ex)
{
string message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
throw new TechnicalException(MethodBase.GetCurrentMethod().DeclaringType.ToString(), string.Format("{0} [9001]", message), ex);
}
}
Method 2 :
public static Lane GetLaneWithIdentifier(int laneIdentifier)
{
AppContext.TraceLogger.VerboseIf(MethodBase.GetCurrentMethod().Name, traceSwitch);
try
{
using (GFC_Entities connexionEF = new GFC_Entities())
{
return connexionEF.Lanes.Where(ln => ln.Identifier == laneIdentifier).FirstOrDefault();
}
}
catch (EntityException ex)
{
string message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
throw new TechnicalException(MethodBase.GetCurrentMethod().DeclaringType.ToString(), string.Format("{0} [9001]", message), ex);
}
}
I would like to make it like :
public static Lane GetLane(int laneIdentifier = 0, string laenCode ="")
and the where clause depends on what parameter I pass. Thank you.