/// <summary> /// Adds a new record into the <c>CDRIdentity</c> table. /// </summary> /// <param name="value">The <see cref="CDRIdentityRow"/> object to be inserted.</param> public virtual void Insert(CDRIdentityRow value) { string sqlStr = "INSERT INTO [dbo].[CDRIdentity] (" + "[id]" + ") VALUES (" + _db.CreateSqlParameterName("Id") + ")"; IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Id", value.Id); cmd.ExecuteNonQuery(); }
/// <summary> /// Converts <see cref="System.Data.DataRow"/> to <see cref="CDRIdentityRow"/>. /// </summary> /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param> /// <returns>A reference to the <see cref="CDRIdentityRow"/> object.</returns> protected virtual CDRIdentityRow MapRow(DataRow row) { CDRIdentityRow mappedObject = new CDRIdentityRow(); DataTable dataTable = row.Table; DataColumn dataColumn; // Column "Id" dataColumn = dataTable.Columns["Id"]; if (!row.IsNull(dataColumn)) { mappedObject.Id = (string)row[dataColumn]; } return(mappedObject); }
static void insert(Cdr_Db_Base pDb, CDRRow pCdrRow) { try { if (pCdrRow.Id != null && pCdrRow.Id.Length == 32) { var _cdrIdentityRow = pDb.CDRIdentityCollection.GetByPrimaryKey(pCdrRow.Id); if (_cdrIdentityRow != null) { pCdrRow.Id = Guid.NewGuid().ToString("N"); //NOTE: openh323 generates duplicate Guids? } _cdrIdentityRow = new CDRIdentityRow { Id = pCdrRow.Id }; pDb.CDRIdentityCollection.Insert(_cdrIdentityRow); } pDb.CDRCollection.Insert(pCdrRow); } catch { pDb.RollbackTransaction(); throw; } }
/// <summary> /// Reads data from the provided data reader and returns /// an array of mapped objects. /// </summary> /// <param name="reader">The <see cref="System.Data.IDataReader"/> object to read data from the table.</param> /// <param name="startIndex">The index of the first record to map.</param> /// <param name="length">The number of records to map.</param> /// <param name="totalRecordCount">A reference parameter that returns the total number /// of records in the reader object if 0 was passed into the method; otherwise it returns -1.</param> /// <returns>An array of <see cref="CDRIdentityRow"/> objects.</returns> protected virtual CDRIdentityRow[] MapRecords(IDataReader reader, int startIndex, int length, ref int totalRecordCount) { if (0 > startIndex) { throw new ArgumentOutOfRangeException("startIndex", startIndex, "StartIndex cannot be less than zero."); } if (0 > length) { throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero."); } int idColumnIndex = reader.GetOrdinal("id"); System.Collections.ArrayList recordList = new System.Collections.ArrayList(); int ri = -startIndex; while (reader.Read()) { ri++; if (ri > 0 && ri <= length) { CDRIdentityRow record = new CDRIdentityRow(); recordList.Add(record); record.Id = Convert.ToString(reader.GetValue(idColumnIndex)); if (ri == length && 0 != totalRecordCount) { break; } } } totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1; return((CDRIdentityRow[])(recordList.ToArray(typeof(CDRIdentityRow)))); }
/// <summary> /// Deletes the specified object from the <c>CDRIdentity</c> table. /// </summary> /// <param name="value">The <see cref="CDRIdentityRow"/> object to delete.</param> /// <returns>true if the record was deleted; otherwise, false.</returns> public bool Delete(CDRIdentityRow value) { return(DeleteByPrimaryKey(value.Id)); }