public override void Visit(CreateProcedureStatement node)
        {
            var    rawProcedureName             = node.ProcedureReference.Name.BaseIdentifier.Value;
            string procedureName                = GetMemberNameWithoutVersionSuffix(node.ProcedureReference.Name);
            string schemaQualifiedProcedureName = $"{node.ProcedureReference.Name.SchemaIdentifier.Value}.{rawProcedureName}";
            string className = $"{procedureName}Procedure";

            ClassDeclarationSyntax classDeclarationSyntax =
                ClassDeclaration(className)
                .WithModifiers(TokenList(Token(SyntaxKind.InternalKeyword)))

                // derive from StoredProcedure
                .WithBaseList(
                    BaseList(
                        SingletonSeparatedList <BaseTypeSyntax>(
                            SimpleBaseType(
                                IdentifierName("StoredProcedure")))))

                // call base("dbo.StoredProcedure")
                .AddMembers(
                    ConstructorDeclaration(
                        Identifier(className))
                    .WithModifiers(
                        TokenList(
                            Token(SyntaxKind.InternalKeyword)))
                    .WithInitializer(
                        ConstructorInitializer(
                            SyntaxKind.BaseConstructorInitializer,
                            ArgumentList(
                                SingletonSeparatedList(
                                    Argument(
                                        LiteralExpression(
                                            SyntaxKind.StringLiteralExpression,
                                            Literal(schemaQualifiedProcedureName)))))))
                    .WithBody(Block()))

                // add fields for each parameter
                .AddMembers(node.Parameters.Select(CreateFieldForParameter).ToArray())

                // add the PopulateCommand method
                .AddMembers(AddPopulateCommandMethod(node, schemaQualifiedProcedureName), AddPopulateCommandMethodForTableValuedParameters(node, procedureName));

            FieldDeclarationSyntax fieldDeclarationSyntax = CreateStaticFieldForClass(className, procedureName);

            var(tvpGeneratorClass, tvpHolderStruct) = CreateTvpGeneratorTypes(node, procedureName);

            MembersToAdd.Add(classDeclarationSyntax.AddSortingKey(this, procedureName));
            MembersToAdd.Add(fieldDeclarationSyntax.AddSortingKey(this, procedureName));
            MembersToAdd.Add(tvpGeneratorClass.AddSortingKey(this, procedureName));
            MembersToAdd.Add(tvpHolderStruct.AddSortingKey(this, procedureName));

            base.Visit(node);
        }
Beispiel #2
0
        public override void Visit(CreateTableStatement node)
        {
            string tableName = node.SchemaObjectName.BaseIdentifier.Value;
            string schemaQualifiedTableName = $"{node.SchemaObjectName.SchemaIdentifier.Value}.{tableName}";
            string className = GetClassNameForTable(tableName);

            ClassDeclarationSyntax classDeclarationSyntax =
                CreateSkeletalClass(className, schemaQualifiedTableName)
                .AddMembers(node.Definition.ColumnDefinitions.Select(CreatePropertyForTableColumn).ToArray());

            FieldDeclarationSyntax field = CreateStaticFieldForClass(className, tableName);

            MembersToAdd.Add(field.AddSortingKey(this, tableName));
            MembersToAdd.Add(classDeclarationSyntax.AddSortingKey(this, tableName));

            base.Visit(node);
        }
Beispiel #3
0
        public override void Visit(CreateTableStatement node)
        {
            string tableName = node.SchemaObjectName.BaseIdentifier.Value;
            string schemaQualifiedTableName = $"{node.SchemaObjectName.SchemaIdentifier.Value}.{tableName}";
            string className = $"{tableName}Table";

            ClassDeclarationSyntax classDeclarationSyntax =
                ClassDeclaration(className)
                .WithModifiers(TokenList(Token(SyntaxKind.InternalKeyword)))
                .WithBaseList(
                    BaseList(
                        SingletonSeparatedList <BaseTypeSyntax>(
                            SimpleBaseType(
                                IdentifierName("Table")))))
                .AddMembers(
                    ConstructorDeclaration(
                        Identifier(className))
                    .WithModifiers(
                        TokenList(
                            Token(SyntaxKind.InternalKeyword)))
                    .WithInitializer(
                        ConstructorInitializer(
                            SyntaxKind.BaseConstructorInitializer,
                            ArgumentList(
                                SingletonSeparatedList(
                                    Argument(
                                        LiteralExpression(
                                            SyntaxKind.StringLiteralExpression,
                                            Literal(schemaQualifiedTableName)))))))
                    .WithBody(Block()))
                .AddMembers(node.Definition.ColumnDefinitions.Select(CreatePropertyForColumn).ToArray());

            FieldDeclarationSyntax field = CreateStaticFieldForClass(className, tableName);

            MembersToAdd.Add(field.AddSortingKey(this, tableName));
            MembersToAdd.Add(classDeclarationSyntax.AddSortingKey(this, tableName));

            base.Visit(node);
        }