public static IntermediaryDataSet_IntermediaryDTO GetInstance(object key, string jbID) { if (key == null) { return(null); } var rawKey = key.ToString(); var parsedKey = int.Parse(rawKey); var foundEntry = new DAL.Repository().GetById <DSS5_SupplyChainFinancialsOptimisation.BO.Intermediary>(parsedKey, false); if (foundEntry == null && !string.IsNullOrWhiteSpace(jbID)) { if (int.TryParse(rawKey, out int _uniqueKey)) { var controller = new SignUpController(); var method = controller.GetType().GetMethod($"Get_{jbID}_DatasourceQueryable"); var records = method.Invoke(controller, new object[] { null }) as IQueryable <DSS5_SupplyChainFinancialsOptimisation.BO.Intermediary>; foundEntry = records.Where(c => c._GetUniqueIdentifier() == _uniqueKey).FirstOrDefault(); } } if (foundEntry != null) { return(new IntermediaryDataSet_IntermediaryDTO(foundEntry)); } return(null); }