コード例 #1
0
        internal MySqlParameterCollection AlignParamsWithDb(MySqlParameterCollection parameterCollection)
        {
            var alignedParams = new MySqlParameterCollection();
            var returnParam   = parameterCollection?.FirstOrDefault(x => x.Direction == ParameterDirection.ReturnValue);

            foreach (var cachedParam in Parameters)
            {
                MySqlParameter alignParam;
                if (cachedParam.Direction == ParameterDirection.ReturnValue)
                {
                    alignParam = returnParam ?? throw new InvalidOperationException($"Attempt to call stored function {FullyQualified} without specifying a return parameter");
                }
                else
                {
                    var index = parameterCollection?.NormalizedIndexOf(cachedParam.Name) ?? -1;
                    alignParam = index >= 0 ? parameterCollection[index] : throw new ArgumentException($"Parameter '{cachedParam.Name}' not found in the collection.");
                }

                if (!alignParam.HasSetDirection)
                {
                    alignParam.Direction = cachedParam.Direction;
                }
                if (!alignParam.HasSetDbType)
                {
                    alignParam.MySqlDbType = cachedParam.MySqlDbType;
                }

                // cached parameters are oredered by ordinal position
                alignedParams.Add(alignParam);
            }

            return(alignedParams);
        }