示例#1
0
        /// <summary>
        /// 创建参数回调
        /// </summary>
        /// <param name="item">参数对象</param>
        protected override void OnCreate(CommandParameter item)
        {
            if (item.Value == null)
            {
                return;
            }
            if (item.Value.GetType() != item.RealType)
            {
                item.Value = TypeExtensions.Convert(item.Value, item.RealType);
            }

            if (item.RealType.IsEnum)
            {
                //item.Properties["MySqlDbType"] = TypeExtensions.Convert("Int64", MySqlProvider.GetDbType());
                item.RealType = typeof(long);
                item.Value    = TypeExtensions.Convert <long>(item.Value);
                return;
            }
            if (item.RealType.IsArray && item.RealType.GetElementType() != typeof(byte))
            {
                item.Properties["MySqlDbType"] = TypeExtensions.Convert("JSON", MySqlProvider.GetDbType());
                item.Value = item.Value == null ? null : JSON.ToJSON(item.Value);
                return;
            }
            if (
                item.RealType == typeof(object) ||
                TypeExtensions.IsAnonymousType(item.RealType) ||
                TypeExtensions.IsInheritFrom(item.RealType, typeof(System.Collections.Generic.IDictionary <string, object>)) ||
                (item.RealType.IsClass && !TypeExtensions.IsSystemBaseType(item.RealType))
                )
            {
                item.Properties["MySqlDbType"] = TypeExtensions.Convert("JSON", MySqlProvider.GetDbType());
                item.RealType = typeof(object);
                item.Value    = item.Value == null ? null : JSON.ToJSON(item.Value);
                return;
            }
        }