コード例 #1
0
        /// <summary>
        /// Persists the object.
        /// </summary>
        public virtual void Persist(Residence persistObject, SqlTransaction sqlTrans)
        {
            // create local variable array for the sql parameters
            SqlParameterHash sqlparams = null;
            // Create a local variable for the connection
            SqlConnection cnn = null;

            // Use the parameter overload or create a new instance
            if (sqlTrans == null)
                cnn = new SqlConnection(Residence.GetConnectionString());

            try
            {
                // discover the parameters
                if (persistObject.Persisted)
                    sqlparams =  SqlHelperParameterCache.GetSpParameterSet(Residence.GetConnectionString(), "gsp_UpdateResidence");
                else
                    sqlparams =  SqlHelperParameterCache.GetSpParameterSet(Residence.GetConnectionString(), "gsp_CreateResidence");

                // Store the parameter for the BorrowerId attribute.
                if (!persistObject.BorrowerIdIsNull)
                    sqlparams["@borrowerId"].Value = persistObject.BorrowerId;
                // Store the parameter for the StreetAddress attribute.
                if (!persistObject.StreetAddressIsNull)
                    sqlparams["@streetAddress"].Value = persistObject.StreetAddress;
                // Store the parameter for the City attribute.
                if (!persistObject.CityIsNull)
                    sqlparams["@city"].Value = persistObject.City;
                // Store the parameter for the State attribute.
                if (!persistObject.StateIsNull)
                    sqlparams["@state"].Value = persistObject.State;
                // Store the parameter for the PostalCode attribute.
                if (!persistObject.PostalCodeIsNull)
                    sqlparams["@postalCode"].Value = persistObject.PostalCode;
                // Store the parameter for the Country attribute.
                if (!persistObject.CountryIsNull)
                    sqlparams["@country"].Value = persistObject.Country;
                // Store the parameter for the BorrowerResidencyDurationMonths attribute.
                if (!persistObject.BorrowerResidencyDurationMonthsIsNull)
                    sqlparams["@borrowerResidencyDurationMonths"].Value = persistObject.BorrowerResidencyDurationMonths;
                // Store the parameter for the BorrowerResidencyDurationYears attribute.
                if (!persistObject.BorrowerResidencyDurationYearsIsNull)
                    sqlparams["@borrowerResidencyDurationYears"].Value = persistObject.BorrowerResidencyDurationYears;
                // Store the parameter for the BorrowerResidencyBasisType attribute.
                if (!persistObject.BorrowerResidencyBasisTypeIsNull)
                    sqlparams["@borrowerResidencyBasisType"].Value = persistObject.BorrowerResidencyBasisType;
                // Store the parameter for the BorrowerResidencyType attribute.
                if (!persistObject.BorrowerResidencyTypeIsNull)
                    sqlparams["@borrowerResidencyType"].Value = persistObject.BorrowerResidencyType;
                // Store the parameter for the Id attribute.
                if (!persistObject.Persisted)
                {
                    // store the create only (historical fixed) values
                }
                else
                {
                    // store the update only (historical changeable) values
                    // Store the parameter for the Id attribute.
                    sqlparams["@id"].Value = persistObject.Id;
                }

                if (sqlTrans == null)
                {
                    // Process using the isolated connection
                    using (cnn)
                    {
                        // open the connection
                        cnn.Open();

                        if (!persistObject.Persisted)
                        {
                            persistObject._id = Convert.ToInt64(SqlHelper.ExecuteScalar(cnn, CommandType.StoredProcedure, "gsp_CreateResidence", sqlparams));
                        }
                        else
                        {
                            SqlHelper.ExecuteNonQuery(cnn, CommandType.StoredProcedure, "gsp_UpdateResidence", sqlparams);
                        }

                        // close the connection after usage
                        cnn.Close();
                    }

                    // nullify the connection var
                    cnn = null;
                }
                else
                {
                    // Process using the shared transaction
                    if (!persistObject.Persisted)
                    {
                        persistObject._id = Convert.ToInt64(SqlHelper.ExecuteScalar(sqlTrans, CommandType.StoredProcedure, "gsp_CreateResidence", sqlparams));
                    }
                    else
                    {
                        SqlHelper.ExecuteNonQuery(sqlTrans, CommandType.StoredProcedure, "gsp_UpdateResidence", sqlparams);
                    }
                }
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }
        }
コード例 #2
0
        /// <summary>
        /// Fills a single instance with data based on its primary key values.
        /// </summary>
        public virtual void Fill(Residence residence, System.Int64 id)
        {
            // create the connection to use
            SqlConnection cnn = new SqlConnection(Residence.GetConnectionString());
            try
            {
                // discover the sql parameters
                SqlParameterHash sqlparams = SqlHelperParameterCache.GetSpParameterSet(Residence.GetConnectionString(), "gsp_SelectResidence");

                using (cnn)
                {
                    // open the connection
                    cnn.Open();

                    // set the parameters
                    sqlparams["@id"].Value = id;

                    // create an instance of the reader to fill.
                    SqlDataReader datareader = SqlHelper.ExecuteReader(cnn, "gsp_SelectResidence", sqlparams);

                    if (datareader.Read())
                        residence.SetMembers(ref datareader);

                    cnn.Close(); // close the connection
                }

                // nullify the connection var
                cnn = null;
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }
        }
コード例 #3
0
 /// <summary>
 /// Persists the object.
 /// </summary>
 public virtual void Persist(Residence persistObject)
 {
     // Make a call to the overloaded method with a null transaction
     Persist(persistObject, null);
 }
コード例 #4
0
        /// <summary>
        /// Deletes the object.
        /// </summary>
        public virtual void Delete(Residence deleteObject)
        {
            // create a new instance of the connection
            SqlConnection cnn = new SqlConnection(Residence.GetConnectionString());
            // create local variable array for the sql parameters
            SqlParameterHash sqlparams = null;

            try
            {
                // discover the parameters
                sqlparams =  SqlHelperParameterCache.GetSpParameterSet(Residence.GetConnectionString(), "gsp_DeleteResidence");

                // Store the parameter for the Id attribute.
                sqlparams["@id"].Value = deleteObject.Id;

                using (cnn)
                {
                    // open the connection
                    cnn.Open();

                    // Execute the stored proc to perform the delete on the instance.
                    SqlHelper.ExecuteNonQuery(cnn, CommandType.StoredProcedure, "gsp_DeleteResidence", sqlparams);

                    // close the connection after usage
                    cnn.Close();
                }

                // nullify the connection var
                cnn = null;
            }
            catch (SqlException sqlex)
            {
                throw sqlex;
            }

            // nullify the reference
            deleteObject = null;
        }