public override DB.DatabaseItem createAsNewItem(DB.DatabaseItem owner, bool save = true) { Table newTable = owner as Table; Database existingDatabase = owner as Database; if (newTable == null) { //look for corresponding table in existingDatabase newTable = (Table)existingDatabase.tables.FirstOrDefault(x => x.name == this.ownerTable.name); } if (newTable != null && newTable.primaryKey == null ) //only create it if htere is not already one { var newPrimaryKey = new PrimaryKey(newTable,this._involvedColumns); newPrimaryKey.name = name; //newPrimaryKey.isOverridden = this.isOverridden; newPrimaryKey.derivedFromItem = this; if (save) newPrimaryKey.save(); return newPrimaryKey; } return null; }