public T Load(T obj, string[] primaryKeyNames) { IList <T> sessions = new List <T>(); IFactory factory = DBHelper.CreateFactory(); DbCommand cmd = null; try { string query = GenerateQuery.CommandTextLoad(obj, primaryKeyNames); cmd = factory.MakeCommand(query); GenerateQuery.PrepareParametersLoad(cmd, obj, primaryKeyNames); IDataReader dre = factory.ExecuteReader(cmd); sessions = Results(dre); if (sessions.Count > 0) { return(sessions[0]); } } catch (Exception ex) { Write2Log.WriteLogs("Generic<T>", string.Format("Load({0} obj, string[] primaryKeyNames)", typeof(T).Name), ex.Message); } finally { cmd.Connection.Close(); cmd.Connection.Dispose(); } return(default(T)); }