예제 #1
0
        public static Expression GetExpression(Context context, ParameterValue value)
        {
            DbType dbType;

            if (DbTypeStore.TryGetDbType(value.ValueType, out dbType))
            {
                return(GetExpressionForKnownDbType(context, value, dbType));
            }

#if FEATURE_TYPE_INFO
            var collectionInterfaceType = value.ValueType.GetInterfaces().FirstOrDefault(x => x.GetTypeInfo().IsGenericType&& x.GetGenericTypeDefinition() == typeof(IEnumerable <>));
#else
            var collectionInterfaceType = value.ValueType.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEnumerable <>));
#endif
            if (collectionInterfaceType != null)
            {
#if FEATURE_GENERIC_TYPE_ARGS
                var innerType = collectionInterfaceType.GenericTypeArguments[0];
#else
                var innerType = collectionInterfaceType.GetGenericArguments()[0];
#endif
                if (DbTypeStore.TryGetDbType(innerType, out dbType))
                {
                    return(GetExpressionForCollectionType(context, value, innerType, dbType));
                }

                throw new NotSupportedException($"Collection parameter of type {innerType} is not supported. Only collections of known data types are supported.");
            }

            throw new NotSupportedException($"Parameter of type {value.ValueType} is not supported.");
        }
예제 #2
0
        public void AddInputOutput(string name, object value, DbType?dbType = null, int?size = null, byte?precision = null, byte?scale = null)
        {
            DbType dbTypeValue;

            if (dbType.HasValue)
            {
                dbTypeValue = dbType.Value;
            }
            else if (value == null)
            {
                throw new ArgumentException($"Argument '{nameof(dbType)}' cannot be null if '{nameof(value)}' is null.");
            }
            else if (!DbTypeStore.TryGetDbType(value.GetType(), out dbTypeValue))
            {
                throw new NotSupportedException($"Parameter of type {value.GetType()} is not supported.");
            }

            m_params.Add(name, GetSpParam(name, dbTypeValue, ParameterDirection.InputOutput, value, size, precision, scale));
        }