/// <summary>
/// Reads the values from an <see cref="IDataReader"/> and assigns the read values to this
/// object's properties. Unlike ReadValues(), this method not only doesn't require
/// all values to be in the <see cref="IDataReader"/>, but also does not require the values in
/// the <see cref="IDataReader"/> to be a defined field for the table this class represents.
/// Because of this, you need to be careful when using this method because values
/// can easily be skipped without any indication.
/// </summary>
/// <param name="source">The object to add the extension method to.</param>
/// <param name="dataRecord">The <see cref="IDataReader"/> to read the values from. Must already be ready to be read from.</param>
        public static void TryReadValues(this CharacterStatusEffectTable source, System.Data.IDataRecord dataRecord)
        {
            for (int i = 0; i < dataRecord.FieldCount; i++)
            {
                switch (dataRecord.GetName(i))
                {
                case "character_id":
                    source.CharacterID = (DemoGame.CharacterID)(DemoGame.CharacterID) dataRecord.GetInt32(i);
                    break;


                case "id":
                    source.ID = (DemoGame.ActiveStatusEffectID)(DemoGame.ActiveStatusEffectID) dataRecord.GetInt32(i);
                    break;


                case "power":
                    source.Power = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i);
                    break;


                case "status_effect_id":
                    source.StatusEffect = (DemoGame.StatusEffectType)(DemoGame.StatusEffectType) dataRecord.GetByte(i);
                    break;


                case "time_left_secs":
                    source.TimeLeftSecs = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i);
                    break;
                }
            }
        }
/// <summary>
/// Reads the values from an <see cref="IDataRecord"/> and assigns the read values to this
/// object's properties. The database column's name is used to as the key, so the value
/// will not be found if any aliases are used or not all columns were selected.
/// </summary>
/// <param name="source">The object to add the extension method to.</param>
/// <param name="dataRecord">The <see cref="IDataRecord"/> to read the values from. Must already be ready to be read from.</param>
        public static void ReadValues(this CharacterStatusEffectTable source, System.Data.IDataRecord dataRecord)
        {
            System.Int32 i;

            i = dataRecord.GetOrdinal("character_id");

            source.CharacterID = (DemoGame.CharacterID)(DemoGame.CharacterID) dataRecord.GetInt32(i);

            i = dataRecord.GetOrdinal("id");

            source.ID = (DemoGame.ActiveStatusEffectID)(DemoGame.ActiveStatusEffectID) dataRecord.GetInt32(i);

            i = dataRecord.GetOrdinal("power");

            source.Power = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("status_effect_id");

            source.StatusEffect = (DemoGame.StatusEffectType)(DemoGame.StatusEffectType) dataRecord.GetByte(i);

            i = dataRecord.GetOrdinal("time_left_secs");

            source.TimeLeftSecs = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i);
        }
        /// <summary>
        /// Updates a <see cref="ActiveStatusEffect"/> in the database.
        /// </summary>
        /// <param name="item">The <see cref="ActiveStatusEffect"/> and <see cref="ActiveStatusEffectID"/> to update.</param>
        void UpdateInDatabase(ASEWithID item)
        {
            // Convert the time
            var secsLeft = GetSecsLeft(item.Value);

            // Create the row
            var values = new CharacterStatusEffectTable
            {
                CharacterID = Character.ID,
                ID = item.ID,
                Power = item.Value.Power,
                TimeLeftSecs = (ushort)secsLeft,
                StatusEffect = item.Value.StatusEffect.StatusEffectType
            };

            // Update the row
            _updateQuery.Execute(values);
        }
        /// <summary>
        /// Inserts a new <see cref="ActiveStatusEffect"/> into the database.
        /// </summary>
        /// <param name="item">The <see cref="ActiveStatusEffect"/> to insert.</param>
        /// <returns>The <see cref="ActiveStatusEffectID"/> for the <paramref name="item"/>.</returns>
        ActiveStatusEffectID InsertInDatabase(ActiveStatusEffect item)
        {
            // Convert the time
            var secsLeft = GetSecsLeft(item);

            // Create the row
            var values = new CharacterStatusEffectTable
            {
                CharacterID = Character.ID,
                ID = new ActiveStatusEffectID(_dbController.ConnectionPool.AutoIncrementValue),
                Power = item.Power,
                TimeLeftSecs = (ushort)secsLeft,
                StatusEffect = item.StatusEffect.StatusEffectType
            };

            // Insert the data, and get the ID
            long id;
            _insertQuery.ExecuteWithResult(values, out id);

            Debug.Assert(id <= int.MaxValue);
            Debug.Assert(id >= int.MinValue);

            // Return the ID
            return new ActiveStatusEffectID((int)id);
        }