public T FindByID <T>(IDbTransaction p_transaction, object p_objectPrimaryKey) where T : new() { TableInformation t_tableInformation = this.GetTableInformations(typeof(T)); SqlCommandHelper t_sqlHelper = new SqlCommandHelper(m_providerConfiguration, t_tableInformation); string t_sql = t_sqlHelper.CreateSelectByPrimaryKey(); IDbCommand cmd = p_transaction.Connection.CreateCommand(); cmd.Transaction = p_transaction; cmd.CommandText = t_sql; IDbDataParameter t_param = cmd.CreateParameter(); t_param.ParameterName = t_sqlHelper.CreateParameterName(t_tableInformation.PrimaryKey.Name); t_param.Value = p_objectPrimaryKey; cmd.Parameters.Add(t_param); IDataReader t_reader = cmd.ExecuteReader(); T t_genericObject = default(T); t_genericObject = new T(); if (t_reader.Read()) { this.PopulateEntity(t_reader, t_tableInformation, t_genericObject); } t_reader.Close(); return(t_genericObject); }
public void ExecuteFindByID(IDbTransaction p_transaction, object p_object) { TableInformation t_tableInformation = this.GetTableInformations(p_object.GetType()); SqlCommandHelper t_sqlHelper = new SqlCommandHelper(m_providerConfiguration, t_tableInformation); string t_sql = t_sqlHelper.CreateSelectByPrimaryKey(); IDbCommand cmd = p_transaction.Connection.CreateCommand(); cmd.Transaction = p_transaction; cmd.CommandText = t_sql; IDbDataParameter t_param = cmd.CreateParameter(); t_param.ParameterName = t_sqlHelper.CreateParameterName(t_tableInformation.PrimaryKey.Name); t_param.Value = p_object.GetType().GetProperty(t_tableInformation.PrimaryKey.PropertyName).GetValue(p_object, null); cmd.Parameters.Add(t_param); IDataReader t_reader = cmd.ExecuteReader(); if (t_reader.Read()) { this.PopulateEntity(t_reader, t_tableInformation, p_object); } t_reader.Close(); }