internal void NotifyShapeDoubleClick(Microsoft.VisualStudio.Modeling.Diagrams.ShapeElement shape) { this.OnShapeDoubleClick(new ModelElementEventArgs() { Shape = shape }); }
protected override void OnChildConfiguring(Microsoft.VisualStudio.Modeling.Diagrams.ShapeElement child, bool createdDuringViewFixup) { base.OnChildConfiguring(child, createdDuringViewFixup); try { if (!this.IsLoading) { //Add a default field to entities if (child.ModelElement is Entity) { var item = child.ModelElement as Entity; var model = item.nHydrateModel; if (item.Fields.Count == 0) { var field = new Field(item.Partition) { DataType = DataTypeConstants.Int, Identity = IdentityTypeConstants.Database, Name = "ID", }; item.Fields.Add(field); //Add then set PK so it will trigger index code field.IsPrimaryKey = true; } #region Pasting //If there are invalid indexes then try to remap them foreach (var index in item.Indexes.Where(x => x.FieldList.Any(z => z == null))) { foreach (var c in index.IndexColumns.Where(x => x.Field == null && x.FieldID != Guid.Empty)) { var f = model.Entities.SelectMany(x => x.Fields).FirstOrDefault(x => x.Id == c.FieldID); if (f != null) { var f2 = item.Fields.FirstOrDefault(x => x.Name == f.Name); if (f2 != null) { c.FieldID = f2.Id; } } } } //Add a PK index if not one if (!item.Indexes.Any(x => x.IndexType == IndexTypeConstants.PrimaryKey) && item.PrimaryKeyFields.Count > 0) { var index = new Index(item.Partition) { IndexType = IndexTypeConstants.PrimaryKey }; item.Indexes.Add(index); var loop = 0; foreach (var field in item.PrimaryKeyFields) { var newIndexColumn = new IndexColumn(item.Partition); index.IndexColumns.Add(newIndexColumn); newIndexColumn.FieldID = field.Id; newIndexColumn.SortOrder = loop; loop++; } } #endregion } else if (child.ModelElement is View) { var item = child.ModelElement as View; if (item.Fields.Count == 0) { var field = new ViewField(item.Partition) { DataType = DataTypeConstants.Int, Name = "Field1", }; item.Fields.Add(field); } } this.OnShapeConfiguring(new ModelElementEventArgs() { Shape = child }); } } catch (Exception ex) { throw; } }