コード例 #1
0
        private void ConvertFunctionsToDatabaseFunctions(EntityModelSchema storageModel, DatabaseSchema schema)
        {
            var composableFunctionsToConvert = storageModel.Functions
                                               .Where(f =>
            {
                var a = f.Annotations.OfType <StoreFunctionMetadataAnnotation>().SingleOrDefault();
                return(a == null || (!a.IsBuiltIn && a.IsComposable));
            });

            var nonComposableFunctionsToConvert = storageModel.Functions
                                                  .Where(f =>
            {
                var a = f.Annotations.OfType <StoreFunctionMetadataAnnotation>().SingleOrDefault();
                return(a != null && !a.IsBuiltIn && !a.IsComposable);
            });

            if (composableFunctionsToConvert.Any() && this.DatabaseFunctionBodyResolver != null)
            {
                foreach (var function in composableFunctionsToConvert)
                {
                    var databaseFunction = this.ConvertToDatabaseFunction(function);
                    this.DatabaseFunctionBodyResolver.ResolveFunctionBody(databaseFunction);
                    schema.Add(databaseFunction);
                }
            }

            if (nonComposableFunctionsToConvert.Any() && this.DatabaseFunctionBodyResolver != null)
            {
                foreach (var function in nonComposableFunctionsToConvert)
                {
                    var storedProcedure = this.ConvertToStoredProcedure(function);
                    this.DatabaseFunctionBodyResolver.ResolveStoredProcedureBody(storedProcedure);
                    if (this.ShouldGenerateCommandText(function))
                    {
                        this.AddCommandTextToAnnotation(function, storedProcedure.Body);
                    }
                    else
                    {
                        schema.Add(storedProcedure);
                    }
                }
            }
        }