Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <param name="propertyDescriptor"></param>
        protected void MapXmlTypeData(object destination, IDbQueryResult source, DbQueryPropertyDescriptor propertyDescriptor)
        {
            var _propertyName  = propertyDescriptor.GetName(false);
            var _propertyValue = source[propertyDescriptor.Prefix, _propertyName];

            if (ObjectUtils.IsXmlType(_propertyValue))
            {
                var _destination = propertyDescriptor.GetValue(destination)
                                   ?? ObjectUtils.CreateInstanceOf(propertyDescriptor.RetrunType);

                var _serializer   = new DbQueryXmlSerializer(OperatingSession.OperationContext);
                var _descriptor   = OperatingSession.OperationContext.DescriptorManager.GetDescriptor(_destination);
                var _deserialized = _serializer.Deserialize(_propertyValue as XmlDocument, _descriptor.PropertyDescriptors, _destination);

                propertyDescriptor.SetValue(destination, _deserialized);
            }
            else if (propertyDescriptor.IsNullable)
            {
                var _destination = propertyDescriptor.GetValue(destination)
                                   ?? ObjectUtils.CreateInstanceOf(propertyDescriptor.RetrunType);

                HandleReferenceTypeData(_destination, source);

                propertyDescriptor.SetValue(destination, _destination);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyDescriptor"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        protected virtual SqlParameter[] CreateParameters(DbQueryPropertyDescriptor propertyDescriptor)
        {
            var _parameters = new ListCollection <SqlParameter>();

            if (propertyDescriptor.HasInputDirection && propertyDescriptor.HasOutputDirection)
            {
                var _inputName  = propertyDescriptor.GetName(DbQueryPropertyDirections.Input);
                var _outputName = propertyDescriptor.GetName(DbQueryPropertyDirections.Output);

                if (_inputName.Equals(_outputName))
                {
                    _parameters.Add(CreateParameter(propertyDescriptor, _inputName, DbQueryPropertyDirections.InputOutput));
                }
                else
                {
                    _parameters.Add(CreateParameter(propertyDescriptor, _inputName, DbQueryPropertyDirections.Input));
                    _parameters.Add(CreateParameter(propertyDescriptor, _outputName, DbQueryPropertyDirections.Output));
                }
            }
            else if (propertyDescriptor.HasOutputDirection)
            {
                var _direction     = DbQueryPropertyDirections.Output;
                var _parameterName = propertyDescriptor.GetName(_direction);

                _parameters.Add(CreateParameter(propertyDescriptor, _parameterName, _direction));
            }
            else if (propertyDescriptor.HasInputDirection)
            {
                var _direction     = DbQueryPropertyDirections.Input;
                var _parameterName = propertyDescriptor.GetName(_direction);

                _parameters.Add(CreateParameter(propertyDescriptor, _parameterName, _direction));
            }

            return(_parameters.ToArray());
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <param name="propertyDescriptor"></param>
        protected virtual void MapValueTypeData(object destination, IDbQueryResult source, DbQueryPropertyDescriptor propertyDescriptor)
        {
            var _propertyName  = propertyDescriptor.GetName(false);
            var _propertyValue = _typeConverter.Convert(propertyDescriptor.RetrunType, source[propertyDescriptor.Prefix, _propertyName]);

            if (ObjectUtils.IsXmlType(_propertyValue) || !ObjectUtils.IsNullOrDefault(_propertyValue))
            {
                propertyDescriptor.SetValue(destination, _propertyValue);
            }
            else
            {
                if (!propertyDescriptor.IsNullable && !propertyDescriptor.IsReadOnly && null != propertyDescriptor.DefaultValue)
                {
                    _propertyValue = propertyDescriptor.GetValue(destination);

                    if (ObjectUtils.IsNullOrDefault(_propertyValue))
                    {
                        var _defaultValue = _typeConverter.Convert(propertyDescriptor.RetrunType, propertyDescriptor.DefaultValue);

                        propertyDescriptor.SetValue(destination, _defaultValue);
                    }
                }
            }
        }