public CreateTableStatement BuildStatement()
        {
            var keyMembers = entitySet.ElementType.KeyMembers.Cast <EdmProperty>().ToArray();

            // Only create a CompositePrimaryKeyStatement if there is a composite primary key.
            // If there is just one key member this is handled using a constraint.
            CompositePrimaryKeyStatement compositePrimaryKeyStatement = null;

            if (keyMembers.Length > 1)
            {
                compositePrimaryKeyStatement = new CompositePrimaryKeyStatementBuilder(keyMembers).BuildStatement();
            }

            var simpleColumnCollection = new ColumnStatementCollectionBuilder(entitySet.ElementType.Properties, keyMembers, defaultCollation).BuildStatement();
            var foreignKeyCollection   = new ForeignKeyStatementBuilder(associationTypeContainer.GetAssociationTypes(entitySet.Name)).BuildStatement();

            var columnStatements = new List <IStatement>();

            columnStatements.AddRange(simpleColumnCollection);
            columnStatements.AddIfNotNull(compositePrimaryKeyStatement);
            columnStatements.AddRange(foreignKeyCollection);

            return(new CreateTableStatement
            {
                TableName = NameCreator.EscapeName(entitySet.Table),
                ColumnStatementCollection = new ColumnStatementCollection(columnStatements)
            });
        }
Пример #2
0
        public CreateTableStatement BuildStatement()
        {
            var simpleColumnCollection = new ColumnStatementCollectionBuilder(entitySet.ElementType.Properties).BuildStatement();
            var primaryKeyStatement    = new PrimaryKeyStatementBuilder(entitySet.ElementType.KeyMembers).BuildStatement();
            var foreignKeyCollection   = new ForeignKeyStatementBuilder(associationTypes).BuildStatement();

            var columnStatements = new List <IStatement>();

            columnStatements.AddRange(simpleColumnCollection);
            columnStatements.Add(primaryKeyStatement);
            columnStatements.AddRange(foreignKeyCollection);

            return(new CreateTableStatement
            {
                TableName = TableNameCreator.CreateTableName(entitySet.Table),
                ColumnStatementCollection = new ColumnStatementCollection(columnStatements)
            });
        }