Exemplo 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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        protected virtual void HandleReferenceTypeData(object destination, IDbQueryResult source)
        {
            if (null != destination && null != source && source.HasResult)
            {
                var _destiDescriptor = OperatingSession.OperationContext.DescriptorManager.GetDescriptor(destination);
                var _resultMapper    = OperatingSession.CreateDbQueryResultMapper(_destiDescriptor.PropertyDescriptors);

                _resultMapper.Map(destination, source);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <param name="propertyDescriptors"></param>
        protected virtual void Map(object destination, IDbQueryResult source, DbQueryPropertyDescriptors propertyDescriptors)
        {
            foreach (var _propertyDescriptor in propertyDescriptors)
            {
                if (_propertyDescriptor.IsMappable && !_propertyDescriptor.IsReadOnly)
                {
                    if (!IsExceptionalType(_propertyDescriptor))
                    {
                        MapValueTypeData(destination, source, _propertyDescriptor);
                    }
                    else
                    {
                        if (_propertyDescriptor.DbType.Equals(SqlDbType.Xml))
                        {
                            MapXmlTypeData(destination, source, _propertyDescriptor);
                        }
                        else
                        {
                            var _destination = _propertyDescriptor.GetValue(destination)
                                               ?? ObjectUtils.CreateInstanceOf(_propertyDescriptor.RetrunType);

                            if (_destination is IValueSerializable)
                            {
                                var _originName   = _propertyDescriptor.GetName(false);
                                var _serializer   = (_destination as IValueSerializable);
                                var _deserialized = _serializer.Deserialize(source[_propertyDescriptor.Prefix, _originName]);

                                if (!ObjectUtils.IsNullOrDefault(_deserialized))
                                {
                                    _propertyDescriptor.SetValue(destination, _deserialized);
                                }
                            }
                            else
                            {
                                HandleReferenceTypeData(_destination, source);

                                _propertyDescriptor.SetValue(destination, _destination);
                            }
                        }
                    }
                }
            }

            MapListTypeData(destination as IList, source);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        protected virtual void MapListTypeData(IList destination, IDbQueryResult source)
        {
            if (null != destination && null != source && source.HasResult)
            {
                var _itemType = ObjectUtils.GetListItemTypeFrom(destination);

                if (null != _itemType)
                {
                    foreach (var _result in source)
                    {
                        var _item = ObjectUtils.CreateInstanceOf(_itemType);

                        if (null != _item)
                        {
                            HandleReferenceTypeData(_item, _result);

                            destination.Add(_item);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
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);
                    }
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="destination"></param>
 /// <param name="source"></param>
 public void Map(object destination, IDbQueryResult source)
 {
     Map(destination, source, PropertyDescriptors);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="queryResult"></param>
 public DbQueryExecutedEventArgs(IDbQueryResult queryResult)
     : base()
 {
     _queryResult = queryResult;
 }