コード例 #1
0
        public void CreateProperty(CreatePropertyCommand createPropertyCommand, object sender, ExecutionCancelEventArgs e)
        {
            IEngine          engine          = sender as IEngine;
            ISchemaService   schemaService   = engine.GetService <ISchemaService>();
            IDatabaseService databaseService = engine.GetService <IDatabaseService>();

            string className    = createPropertyCommand.ClassName;
            string propertyName = createPropertyCommand.Name;

            string propertyType = createPropertyCommand.Type.ToString();

            string columnName = createPropertyCommand.ColumnName;
            DbType columnType = databaseService.GetDbType(createPropertyCommand.Type, createPropertyCommand.StringLength);;

            string tableName = schemaService.GetTableForClass(className);

            //Add a property to the class
            schemaService.CreateProperty(className, propertyName, propertyType);

            //Set the nullability of the property
            schemaService.SetPropertyMetaData(className, propertyName, PropertyMetaData.Nullable, createPropertyCommand.Nullable);

            //Add a column to the table
            schemaService.CreateColumn(tableName, columnName, columnType);

            //Set the nullability of the column
            schemaService.SetColumnMetaData(tableName, columnName, ColumnMetaData.Nullable, createPropertyCommand.Nullable);

            //Map the property to the column in the schema
            schemaService.MapPropertyToColumn(className, propertyName, tableName, columnName);
        }
コード例 #2
0
        public void CreateRelationship(CreatePropertyCommand createPropertyCommand, object sender, Puzzle.SideFX.Framework.Execution.ExecutionCancelEventArgs e)
        {
            IEngine          engine          = sender as IEngine;
            ISchemaService   schemaService   = engine.GetService <ISchemaService>();
            IDatabaseService databaseService = engine.GetService <IDatabaseService>();

            string className    = createPropertyCommand.ClassName;
            string propertyName = createPropertyCommand.Name;

            string propertyType = createPropertyCommand.Type.ToString();

            string columnName = createPropertyCommand.ColumnName;
            DbType columnType = DbType.Int32; //TODO: Get the column of the identity property

            string tableName = schemaService.GetTableForClass(className);

            switch (createPropertyCommand.Multiplicity)
            {
            case Multiplicity.OneToMany:
            case Multiplicity.OneToOne:

                //Add a property to the class
                schemaService.CreateProperty(className, propertyName, propertyType);

                //Set the nullability of the property
                schemaService.SetPropertyMetaData(className, propertyName, PropertyMetaData.Nullable, createPropertyCommand.Nullable);

                //Add a column to the table
                schemaService.CreateColumn(tableName, columnName, columnType);

                //Set the nullability of the column
                schemaService.SetColumnMetaData(tableName, columnName, ColumnMetaData.Nullable, createPropertyCommand.Nullable);

                //Map the property to the column in the schema
                schemaService.MapPropertyToColumn(className, propertyName, tableName, columnName);

                break;

            case Multiplicity.ManyToMany:

                //Add a property to the class
                schemaService.CreateListProperty(className, propertyName, propertyType);

                //Add a many-many table
                //schemaService.CreateTable(tableName, columnName, columnType);

                break;

            case Multiplicity.ManyToOne:

                //Add a property to the class
                schemaService.CreateListProperty(className, propertyName, propertyType);

                //Add a column to the table
                //schemaService.CreateColumn(tableName, columnName, columnType);

                break;
            }
        }
コード例 #3
0
        public void OnExecuting(object sender, ExecutionCancelEventArgs e)
        {
            CreateClassCommand createClassCommand = CreateClassCommand.Evaluate(e.Command);

            if (createClassCommand == null)
            {
                return;
            }
            IEngine        engine        = sender as IEngine;
            ISchemaService schemaService = engine.GetService <ISchemaService>();

            string name         = createClassCommand.Name;
            string propertyName = "Id";
            string propertyType = "System.Int32";
            string columnName   = name + "Id";
            DbType columnType   = DbType.Int32;

            //Add the class to the schema
            schemaService.CreateClass(name);

            //Add a property to the class
            schemaService.CreateProperty(name, propertyName, propertyType);

            //Mark the property as an identity property
            schemaService.SetPropertyMetaData(name, propertyName, PropertyMetaData.Identity, true);

            //Mark the property as not nullable
            schemaService.SetPropertyMetaData(name, propertyName, PropertyMetaData.Nullable, false);

            //Mark the property as assigned by the data source
            schemaService.SetPropertyMetaData(name, propertyName, PropertyMetaData.SourceAssigned, true);

            //Add the table to the schema
            schemaService.CreateTable(createClassCommand.TableName);

            //Add a column to the table
            schemaService.CreateColumn(createClassCommand.TableName, columnName, columnType);

            //Mark the column as a primary key column
            schemaService.SetColumnMetaData(createClassCommand.TableName, columnName, ColumnMetaData.PrimaryKey, true);

            //Mark the column as not nullable
            schemaService.SetColumnMetaData(createClassCommand.TableName, columnName, ColumnMetaData.Nullable, false);

            //Mark the column as an auto increasing column
            schemaService.SetColumnMetaData(createClassCommand.TableName, columnName, ColumnMetaData.AutoIncreaser, true);

            //Map the class to the table in the schema
            schemaService.MapClassToTable(name, createClassCommand.TableName);

            //Map the property to the column in the schema
            schemaService.MapPropertyToColumn(name, propertyName, createClassCommand.TableName, columnName);
        }