Example #1
0
        public void ExecuteUpdateCommand(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.CreateUpdate(p_object);

            IDbCommand t_cmd = p_transaction.Connection.CreateCommand();

            foreach (FieldInformation t_currFieldinformation in t_tableInformation.Fields)
            {
                if (t_currFieldinformation.IsPrimaryKey)
                {
                    continue;
                }

                IDbDataParameter t_param = t_cmd.CreateParameter();
                t_param.ParameterName = t_sqlHelper.CreateParameterName(t_currFieldinformation.Name);
                t_param.Value         = p_object.GetType().GetProperty(t_currFieldinformation.PropertyName).GetValue(p_object, null);
                t_cmd.Parameters.Add(t_param);
            }

            IDbDataParameter t_paramPK = t_cmd.CreateParameter();

            t_paramPK.ParameterName = t_sqlHelper.CreateParameterName(t_tableInformation.PrimaryKey.Name);
            t_paramPK.Value         = p_object.GetType().GetProperty(t_tableInformation.PrimaryKey.PropertyName).GetValue(p_object, null);
            t_cmd.Parameters.Add(t_paramPK);

            t_cmd.CommandText = t_sql.ToString();
            t_cmd.Transaction = p_transaction;
            t_cmd.ExecuteNonQuery();
        }
Example #2
0
        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);
        }
Example #3
0
        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();
        }
Example #4
0
        public void ExecuteDeleteCommand(IDbTransaction p_transaction, object p_object)
        {
            TableInformation t_tableInformation = this.GetTableInformations(p_object.GetType());
            SqlCommandHelper t_sqlHelper        = new SqlCommandHelper(this.m_providerConfiguration, t_tableInformation);

            string t_sql = t_sqlHelper.CreateDeleteByPrimaryKey();

            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);

            cmd.ExecuteNonQuery();
        }