/// <summary> /// Factory method. Loads a <see cref="D06_Country"/> object from the given D06_CountryDto. /// </summary> /// <param name="data">The <see cref="D06_CountryDto"/>.</param> /// <returns>A reference to the fetched <see cref="D06_Country"/> object.</returns> internal static D06_Country GetD06_Country(D06_CountryDto data) { D06_Country obj = new D06_Country(); obj.Fetch(data); return(obj); }
private void Child_Update() { if (!IsDirty) { return; } var dto = new D06_CountryDto(); dto.Country_ID = Country_ID; dto.Country_Name = Country_Name; using (var dalManager = DalFactorySelfLoad.GetManager()) { var args = new DataPortalHookArgs(dto); OnUpdatePre(args); var dal = dalManager.GetProvider <ID06_CountryDal>(); using (BypassPropertyChecks) { var resultDto = dal.Update(dto); args = new DataPortalHookArgs(resultDto); } OnUpdatePost(args); // flushes all pending data operations FieldManager.UpdateChildren(this); } }
/// <summary> /// Loads a <see cref="D06_Country"/> object from the given <see cref="D06_CountryDto"/>. /// </summary> /// <param name="data">The D06_CountryDto to use.</param> private void Fetch(D06_CountryDto data) { // Value properties LoadProperty(Country_IDProperty, data.Country_ID); LoadProperty(Country_NameProperty, data.Country_Name); var args = new DataPortalHookArgs(data); OnFetchRead(args); }
private D06_CountryDto Fetch(SafeDataReader dr) { var d06_Country = new D06_CountryDto(); // Value properties d06_Country.Country_ID = dr.GetInt32("Country_ID"); d06_Country.Country_Name = dr.GetString("Country_Name"); return(d06_Country); }
/// <summary> /// Factory method. Loads a <see cref="D06_Country"/> object from the given D06_CountryDto. /// </summary> /// <param name="data">The <see cref="D06_CountryDto"/>.</param> /// <returns>A reference to the fetched <see cref="D06_Country"/> object.</returns> internal static D06_Country GetD06_Country(D06_CountryDto data) { D06_Country obj = new D06_Country(); // show the framework that this is a child object obj.MarkAsChild(); obj.Fetch(data); obj.MarkOld(); return(obj); }
/// <summary> /// Inserts a new D06_Country object in the database. /// </summary> /// <param name="d06_Country">The D06 Country DTO.</param> /// <returns>The new <see cref="D06_CountryDto"/>.</returns> public D06_CountryDto Insert(D06_CountryDto d06_Country) { using (var ctx = ConnectionManager <SqlConnection> .GetManager("DeepLoad")) { using (var cmd = new SqlCommand("AddD06_Country", ctx.Connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Parent_SubContinent_ID", d06_Country.Parent_SubContinent_ID).DbType = DbType.Int32; cmd.Parameters.AddWithValue("@Country_ID", d06_Country.Country_ID).Direction = ParameterDirection.Output; cmd.Parameters.AddWithValue("@Country_Name", d06_Country.Country_Name).DbType = DbType.String; cmd.ExecuteNonQuery(); d06_Country.Country_ID = (int)cmd.Parameters["@Country_ID"].Value; } } return(d06_Country); }
/// <summary> /// Updates in the database all changes made to the D06_Country object. /// </summary> /// <param name="d06_Country">The D06 Country DTO.</param> /// <returns>The updated <see cref="D06_CountryDto"/>.</returns> public D06_CountryDto Update(D06_CountryDto d06_Country) { using (var ctx = ConnectionManager <SqlConnection> .GetManager("DeepLoad")) { using (var cmd = new SqlCommand("UpdateD06_Country", ctx.Connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Country_ID", d06_Country.Country_ID).DbType = DbType.Int32; cmd.Parameters.AddWithValue("@Country_Name", d06_Country.Country_Name).DbType = DbType.String; var rowsAffected = cmd.ExecuteNonQuery(); if (rowsAffected == 0) { throw new DataNotFoundException("D06_Country"); } } } return(d06_Country); }
private void Child_Insert(D04_SubContinent parent) { var dto = new D06_CountryDto(); dto.Parent_SubContinent_ID = parent.SubContinent_ID; dto.Country_Name = Country_Name; using (var dalManager = DalFactorySelfLoad.GetManager()) { var args = new DataPortalHookArgs(dto); OnInsertPre(args); var dal = dalManager.GetProvider <ID06_CountryDal>(); using (BypassPropertyChecks) { var resultDto = dal.Insert(dto); LoadProperty(Country_IDProperty, resultDto.Country_ID); args = new DataPortalHookArgs(resultDto); } OnInsertPost(args); // flushes all pending data operations FieldManager.UpdateChildren(this); } }