Esempio n. 1
0
        internal static List <EdmSchemaError> LoadItems(
            DbProviderManifest manifest,
            IList <Schema> somSchemas,
            ItemCollection itemCollection)
        {
            List <EdmSchemaError>    edmSchemaErrorList = new List <EdmSchemaError>();
            IEnumerable <GlobalItem> globalItems        = EdmItemCollection.LoadSomSchema(somSchemas, manifest, itemCollection);
            List <string>            stringList         = new List <string>();

            foreach (GlobalItem globalItem in globalItems)
            {
                if (globalItem.BuiltInTypeKind == BuiltInTypeKind.EdmFunction && globalItem.DataSpace == DataSpace.SSpace)
                {
                    EdmFunction   edmFunction = (EdmFunction)globalItem;
                    StringBuilder builder     = new StringBuilder();
                    EdmFunction.BuildIdentity <FunctionParameter>(builder, edmFunction.FullName, (IEnumerable <FunctionParameter>)edmFunction.Parameters, (Func <FunctionParameter, TypeUsage>)(param => MetadataHelper.ConvertStoreTypeUsageToEdmTypeUsage(param.TypeUsage)), (Func <FunctionParameter, ParameterMode>)(param => param.Mode));
                    string str = builder.ToString();
                    if (stringList.Contains(str))
                    {
                        edmSchemaErrorList.Add(new EdmSchemaError(Strings.DuplicatedFunctionoverloads((object)edmFunction.FullName, (object)str.Substring(edmFunction.FullName.Length)).Trim(), 174, EdmSchemaErrorSeverity.Error));
                        continue;
                    }
                    stringList.Add(str);
                }
                globalItem.SetReadOnly();
                itemCollection.AddInternal(globalItem);
            }
            return(edmSchemaErrorList);
        }
        internal static List <EdmSchemaError> LoadItems(
            DbProviderManifest manifest, IList <Schema> somSchemas,
            ItemCollection itemCollection)
        {
            var errors = new List <EdmSchemaError>();
            // Convert the schema, if model schema, then we use the EDM provider manifest, otherwise use the
            // store provider manifest
            var newGlobalItems            = LoadSomSchema(somSchemas, manifest, itemCollection);
            var tempCTypeFunctionIdentity = new List <string>();

            // No errors, so go ahead and add the types and make them readonly
            foreach (var globalItem in newGlobalItems)
            {
                // If multiple function parameter and return types expressed in SSpace map to the same
                // CSpace type (e.g., SqlServer.decimal and SqlServer.numeric both map to Edm.Decimal),
                // we need to guard against attempts to insert duplicate functions into the collection.
                //
                if (globalItem.BuiltInTypeKind == BuiltInTypeKind.EdmFunction &&
                    globalItem.DataSpace == DataSpace.SSpace)
                {
                    var function = (EdmFunction)globalItem;

                    var sb = new StringBuilder();
                    EdmFunction.BuildIdentity(
                        sb,
                        function.FullName,
                        function.Parameters,
                        // convert function parameters to C-side types
                        (param) => MetadataHelper.ConvertStoreTypeUsageToEdmTypeUsage(param.TypeUsage),
                        (param) => param.Mode);
                    var cTypeFunctionIdentity = sb.ToString();

                    // Validate identity
                    if (tempCTypeFunctionIdentity.Contains(cTypeFunctionIdentity))
                    {
                        errors.Add(
                            new EdmSchemaError(
                                Strings.DuplicatedFunctionoverloads(
                                    function.FullName, cTypeFunctionIdentity.Substring(function.FullName.Length)).Trim() /*parameters*/,
                                (int)ErrorCode.DuplicatedFunctionoverloads,
                                EdmSchemaErrorSeverity.Error));
                        continue;
                    }

                    tempCTypeFunctionIdentity.Add(cTypeFunctionIdentity);
                }
                globalItem.SetReadOnly();
                itemCollection.AddInternal(globalItem);
            }
            return(errors);
        }