public override MetaFunction GetFunction(MethodInfo method)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            MetaFunction func = null;

            this.metaFunctions.TryGetValue(new MetaPosition(method), out func);
            return(func);
        }
Example #2
0
        public override MetaFunction GetFunction(MethodInfo method)
        {
            if (method == null)
            {
                throw Error.ArgumentNull("method");
            }
            this.InitFunctions();
            MetaFunction function = null;

            this.metaFunctions.TryGetValue(new MetaPosition(method), out function);
            return(function);
        }
Example #3
0
        public override MetaFunction GetFunction(MethodInfo method)
        {
            if (method == (MethodInfo)null)
            {
                throw System.Data.Linq.Mapping.Error.ArgumentNull("method");
            }
            InitFunctions();
            MetaFunction value = null;

            metaFunctions.TryGetValue(new MetaPosition(method), out value);
            return(value);
        }
Example #4
0
        /// <summary>
        /// Create a list of sql parameters for the specified method call expression,
        /// taking into account any explicit typing applied to the parameters via the
        /// Parameter attribute.
        /// </summary>        
        private List<SqlExpression> GetFunctionParameters(MethodCallExpression mce, MetaFunction function) {
            List<SqlExpression> sqlParams = new List<SqlExpression>(mce.Arguments.Count);

            // create sql parameters for each method parameter 
            for (int i = 0, n = mce.Arguments.Count; i < n; i++) {
                SqlExpression newParamExpression = this.VisitExpression(mce.Arguments[i]);

                // If the parameter explicitly specifies a type in metadata,
                // use it as the provider type.
                MetaParameter currMetaParam = function.Parameters[i];
                if (!string.IsNullOrEmpty(currMetaParam.DbType)) {
                    SqlSimpleTypeExpression typeExpression = newParamExpression as SqlSimpleTypeExpression;
                    if (typeExpression != null) {
                        // determine provider type, and update the parameter expression
                        ProviderType providerType = typeProvider.Parse(currMetaParam.DbType);
                        typeExpression.SetSqlType(providerType);
                    }
                }
                sqlParams.Add(newParamExpression);
            }

            return sqlParams;
        }
Example #5
0
        /// <summary>
        /// Translate a call to a stored procedure
        /// </summary>             
        private SqlNode TranslateStoredProcedureCall(MethodCallExpression mce, MetaFunction function) {
            if (!this.outerNode) {
                throw Error.SprocsCannotBeComposed();
            }

            // translate method call into sql function call
            List<SqlExpression> sqlParams = GetFunctionParameters(mce, function);

            SqlStoredProcedureCall spc = new SqlStoredProcedureCall(function, null, sqlParams, mce);

            Type returnType = mce.Method.ReturnType;
            if (returnType.IsGenericType &&
                (returnType.GetGenericTypeDefinition() == typeof(IEnumerable<>) ||
                returnType.GetGenericTypeDefinition() == typeof(ISingleResult<>))) {

                // Since this is a single rowset returning sproc, we use the one
                // and only root metatype.
                MetaType rowType = function.ResultRowTypes[0].InheritanceRoot;
                
                SqlUserRow rowExp = new SqlUserRow(rowType, this.typeProvider.GetApplicationType((int)ConverterSpecialTypes.Row), spc, mce);
                spc.Projection = this.translator.BuildProjection(rowExp, rowType, this.allowDeferred, null, mce);
            }
            else if (!(
                typeof(IMultipleResults).IsAssignableFrom(returnType)
                || returnType == typeof(int)
                || returnType == typeof(int?)
                )) {
                throw Error.InvalidReturnFromSproc(returnType);
            }

            return spc;
        }
Example #6
0
        /// <summary>
        /// Translate a call to a table valued function expression into a sql select.
        /// </summary>             
        private SqlNode TranslateTableValuedFunction(MethodCallExpression mce, MetaFunction function) {
            // translate method call into sql function call
            List<SqlExpression> sqlParams = GetFunctionParameters(mce, function);
            SqlTableValuedFunctionCall functionCall = sql.TableValuedFunctionCall(function.ResultRowTypes[0].InheritanceRoot, mce.Method.ReturnType, function.MappedName, sqlParams, mce);

            SqlAlias alias = new SqlAlias(functionCall);
            SqlAliasRef aref = new SqlAliasRef(alias);

            // Build default projection           
            SqlExpression projection = this.translator.BuildProjection(aref, function.ResultRowTypes[0].InheritanceRoot, this.allowDeferred, null, mce);

            SqlSelect select = new SqlSelect(projection, alias, mce);
            return select;
        }
		internal SqlStoredProcedureCall(MetaFunction function, SqlExpression projection, IEnumerable<SqlExpression> args, Expression source)
			: base(SqlNodeType.StoredProcedureCall, projection, args, source) {
			if (function == null)
				throw Error.ArgumentNull("function");
			this.function = function;
			}