Beispiel #1
0
        /// <summary>
        /// Gets the unique key and adds to the <see cref="DatabaseParameters"/> for the listed key values.
        /// </summary>
        /// <param name="parameters">The <see cref="DatabaseParameters"/>.</param>
        /// <param name="operationType">The single <see cref="Mapper.OperationTypes"/> that indicates that a <see cref="Mapper.OperationTypes.Create"/> is being performed;
        /// therefore any key properties marked as <see cref="PropertyMapperCustomBase{TSrce, TSrceProperty}.IsUniqueKeyAutoGeneratedOnCreate"/> have a parameter direction of
        /// <see cref="ParameterDirection.Output"/> versus <see cref="ParameterDirection.Input"/>.</param>
        /// <param name="keys">The unique key values.</param>
        public void GetKeyParams(DatabaseParameters parameters, OperationTypes operationType, params IComparable[] keys)
        {
            var uq = operationType == OperationTypes.Create ? UniqueKey.Where(x => !x.IsUniqueKeyAutoGeneratedOnCreate).ToArray() : UniqueKey;

            if (keys == null || keys.Length != uq.Length)
            {
                throw new ArgumentException("The number of keys supplied must equal the number of properties identified as IsUniqueKey.", nameof(keys));
            }

            for (int i = 0; i < keys.Length; i++)
            {
                var map = (IDatabasePropertyMapper)uq[i];
                var dir = (operationType == OperationTypes.Create && map.IsUniqueKeyAutoGeneratedOnCreate) ? ParameterDirection.Output : ParameterDirection.Input;
                if (map.DestDbType.HasValue)
                {
                    parameters.AddParameter(map.DestParameterName, keys[0], map.DestDbType.Value, dir);
                }
                else
                {
                    parameters.AddParameter(map.DestParameterName, keys[0], dir);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Sets the destination <see cref="DatabaseParameters"/> from the source property value.
        /// </summary>
        /// <param name="value">The source value.</param>
        /// <param name="parameters">The <see cref="DatabaseParameters"/>.</param>
        /// <param name="operationType">The single <see cref="Mapper.OperationTypes"/> being performed to enable selection.</param>
        public void SetDestValue(TSrce value, DatabaseParameters parameters, OperationTypes operationType)
        {
            if (!OperationTypes.HasFlag(operationType))
            {
                return;
            }

            if (parameters.Contains(DestParameterName))
            {
                return;
            }

            if (_mapToDbOverride != null)
            {
                _mapToDbOverride(value, parameters, operationType);
                return;
            }

            var val = GetSrceValue(value, operationType);

            if (Mapper != null)
            {
                var em = (IDatabaseMapper)Mapper;
                em.MapToDb(val, parameters, operationType, this);
            }
            else
            {
                if (DestDbType.HasValue)
                {
                    parameters.AddParameter(DestParameterName, Converter == null ? val : Converter.ConvertToDest(val), dbType: DestDbType.Value);
                }
                else
                {
                    parameters.AddParameter(DestParameterName, Converter == null ? val : Converter.ConvertToDest(val));
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Sets the destination <see cref="DatabaseParameters"/> from the source property value.
 /// </summary>
 /// <param name="value">The source value.</param>
 /// <param name="parameters">The <see cref="DatabaseParameters"/>.</param>
 /// <param name="operationType">The single <see cref="Mapper.OperationTypes"/> being performed to enable selection.</param>
 void IDatabasePropertyMapper.SetDestValue(object value, DatabaseParameters parameters, OperationTypes operationType)
 {
     SetDestValue((TSrce)value, parameters, operationType);
 }
Beispiel #4
0
 /// <summary>
 /// Gets the unique key and adds to the <see cref="DatabaseParameters"/> from an entity <paramref name="value"/>.
 /// </summary>
 /// <param name="parameters">The <see cref="DatabaseParameters"/>.</param>
 /// <param name="operationType">The single <see cref="Mapper.OperationTypes"/> that indicates that a <see cref="Mapper.OperationTypes.Create"/> is being performed;
 /// therefore any key properties marked as <see cref="PropertyMapperCustomBase{TSrce, TSrceProperty}.IsUniqueKeyAutoGeneratedOnCreate"/> have a parameter direction of
 /// <see cref="ParameterDirection.Output"/> versus <see cref="ParameterDirection.Input"/>.</param>
 /// <param name="value">The entity value.</param>
 void IDatabaseMapper.GetKeyParams(DatabaseParameters parameters, OperationTypes operationType, object value)
 {
     GetKeyParams(parameters, operationType, (TSrce)value);
 }
Beispiel #5
0
 /// <summary>
 /// Extension opportunity when performing a <see cref="MapToDb(TSrce, DatabaseParameters, OperationTypes, object)"/>.
 /// </summary>
 /// <param name="value">The entity value.</param>
 /// <param name="parameters">The <see cref="DatabaseParameters"/>.</param>
 /// <param name="operationType">The single <see cref="Mapper.OperationTypes"/> being performed to enable selection.</param>
 /// <param name="data">An optional (additional) data object.</param>
 protected virtual void OnMapToDb(TSrce value, DatabaseParameters parameters, OperationTypes operationType, object data)
 {
 }
Beispiel #6
0
 /// <summary>
 /// Updates the <see cref="DatabaseParameters"/> mapping values from the source entity <paramref name="value"/>.
 /// </summary>
 /// <param name="value">The entity value.</param>
 /// <param name="parameters">The <see cref="DatabaseParameters"/>.</param>
 /// <param name="operationType">The single <see cref="Mapper.OperationTypes"/> being performed to enable selection.</param>
 /// <param name="data">An optional (additional) data object.</param>
 void IDatabaseMapper.MapToDb(object value, DatabaseParameters parameters, OperationTypes operationType, object data)
 {
     MapToDb((TSrce)value, parameters, operationType, data);
 }