Example #1
0
            public Meta(Expression expression, DynamicStoredProcedureResults value)
                : base(expression, BindingRestrictions.GetInstanceRestriction(expression, value), value)
            {
                Contract.Requires(expression != null);
                Contract.Requires(value != null);

                results  = value;
                restrict = BindingRestrictions.GetInstanceRestriction(expression, results);
            }
Example #2
0
        public DynamicStoredProcedureResultsAwaiter(
            DynamicStoredProcedureResults results,
            Task toWait)
        {
            Contract.Requires(results != null);
            Contract.Requires(toWait != null);

            this.results = results;
            this.toWait  = toWait;
        }
Example #3
0
        public static object Create(DynamicStoredProcedureResults results, Task task, bool continueOnCaller)
        {
            Contract.Requires(results != null);
            Contract.Requires(task != null);
            Contract.Ensures(Contract.Result <object>() != null);
#if NET40
            return(Activator.CreateInstance(dynamicAwaiterType.Value, results, task, continueOnCaller));
#else
            return(new DynamicStoredProcedureResultsAwaiter(results, task, continueOnCaller));
#endif
        }
Example #4
0
        public DynamicStoredProcedureResultsAwaiter(
            DynamicStoredProcedureResults results,
            Task toWait,
            bool continueOnCaller)
            : this(results, toWait)
        {
            Contract.Requires(results != null);
            Contract.Requires(toWait != null);

            this.awaiter = toWait.ConfigureAwait(continueOnCaller).GetAwaiter();
        }
Example #5
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            var parameters = new List <IStoredProcedureParameter>();

            for (int i = 0; i < binder.CallInfo.ArgumentCount; ++i)
            {
                // the first item in ICSharpInvokeOrInvokeMemberBinder.Arguments seems to be this object (c-style method calling)
                var argument  = getArgumentInfo(binder, i + 1);
                var direction = getParameterDirection(argument);
                var parmName  = getParameterName(argument);
                var arg       = args[i];

                if (arg == null || arg == DBNull.Value)
                {
                    if (string.IsNullOrWhiteSpace(parmName))
                    {
                        throw new StoredProcedureException(namedParameterException);
                    }

                    parameters.Add(new InputParameter(parmName, DBNull.Value));
                    continue;
                }

                var idx     = i;  // store the value, otherwise when it is lifted to lambdas, i will be the binder.CallInfo.ArgumentCount
                var argType = arg.GetType();
                var dbType  = argType.InferDbType();

                if (argType.IsEnumeratedType())
                {
                    // it is a TableValuedParameter, so we need to get the SQL Server type name
                    var itemType = argType.GetEnumeratedType();
                    var attr     = itemType.GetCustomAttributes(false)
                                   .OfType <TableValuedParameterAttribute>()
                                   .FirstOrDefault();

                    if (attr == null)
                    {
                        if (string.IsNullOrWhiteSpace(parmName))
                        {
                            throw new StoredProcedureException(namedParameterException);
                        }

                        parameters.Add(itemType.CreateTableValuedParameter(parmName, arg));
                    }
                    else
                    {
                        if (string.IsNullOrWhiteSpace(attr.Name) && string.IsNullOrWhiteSpace(parmName))
                        {
                            throw new StoredProcedureException("When using the dynamic syntax, parameters must be passed by name.\nBecause you're passing a Table Valued Parameter, if the TableValuedParameterAttribute decorating your class has the Name set, it will be used instead.");
                        }

                        parameters.Add(
                            new TableValuedParameter(attr.Name ?? parmName,
                                                     (IEnumerable)arg,
                                                     itemType,
                                                     attr.TableName,
                                                     attr.Schema));
                    }
                }
                else if (argType == typeof(DataTable))
                {
                    parameters.Add(new TableValuedParameter(parmName, (DataTable)arg));
                }
                else if (dbType == DbType.Object)
                {
                    parameters.AddRange(argType.GetParameters(arg));
                }
                else if (direction == ParameterDirection.Output)
                {
                    if (string.IsNullOrWhiteSpace(parmName))
                    {
                        throw new StoredProcedureException(namedParameterException);
                    }

                    VerifySynchronousExecutionMode(executionMode);

                    if ("returnvalue".Equals(parmName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        parameters.Add(new ReturnValueParameter(r => args[idx] = r));
                    }
                    else
                    {
                        parameters.Add(new OutputParameter(parmName, o => args[idx] = o, dbType));
                    }
                }
                else if (direction == ParameterDirection.InputOutput)
                {
                    if (string.IsNullOrWhiteSpace(parmName))
                    {
                        throw new StoredProcedureException(namedParameterException);
                    }

                    VerifySynchronousExecutionMode(executionMode);

                    parameters.Add(new InputOutputParameter(parmName, o => args[idx] = o, arg, dbType));
                }
                else if (string.IsNullOrWhiteSpace(parmName))
                {
                    throw new StoredProcedureException(namedParameterException);
                }
                else
                {
                    parameters.Add(new InputParameter(parmName, arg, dbType));
                }
            }

            result = new DynamicStoredProcedureResults(
                connection,
                schema ?? "dbo",
                binder.Name,
                timeout,
                parameters,
                transformers,
                executionMode,
                hasResults,
                token);

            return(true);
        }