public virtual void UiBtnCommandDownAction(Object param) { if ((PrimaryKeyPropertiesIndex > -1) && (PrimaryKeyPropertiesIndex < PrimaryKeyProperties.Count - 1)) { PrimaryKeyProperties.Move(PrimaryKeyPropertiesIndex, PrimaryKeyPropertiesIndex + 1); //PrimaryKeyPropertiesIndex = PrimaryKeyPropertiesIndex + 1; } }
public virtual void UiBtnCommandUpAction(Object param) { if ((PrimaryKeyPropertiesIndex > 0) && (PrimaryKeyPropertiesIndex < PrimaryKeyProperties.Count)) { PrimaryKeyProperties.Move(PrimaryKeyPropertiesIndex, PrimaryKeyPropertiesIndex - 1); //PrimaryKeyPropertiesIndex = PrimaryKeyPropertiesIndex - 1; } }
public virtual void UiBtnCommandToPrimaryAction(Object param) { if ((EntityPropertiesIndex > -1) && (EntityPropertiesIndex < EntityProperties.Count)) { var itm = EntityProperties[EntityPropertiesIndex]; if (!PrimaryKeyProperties.Contains(itm)) { PrimaryKeyProperties.Add(itm); } } }
public virtual void UiBtnCommandFromPrimaryAction(Object param) { if ((PrimaryKeyPropertiesIndex > -1) && (PrimaryKeyPropertiesIndex < PrimaryKeyProperties.Count)) { PrimaryKeyProperties.RemoveAt(PrimaryKeyPropertiesIndex); if (PrimaryKeyProperties.Count <= PrimaryKeyPropertiesIndex) { if (PrimaryKeyPropertiesIndex > -1) { PrimaryKeyPropertiesIndex -= 1; } } } }
public virtual void UiBtnCommandAllFromPrimaryAction(Object param) { PrimaryKeyProperties.Clear(); PrimaryKeyPropertiesIndex = -1; }
public void OnEntityNonScalarPropertiesIndexChanged() { _RefreshCanExecute = false; masterCodeClassFullName = ""; PrimaryKeyProperties.Clear(); PrincipalNonScalarProperties.Clear(); PrincipalNonScalarPropertiesIndex = -1; if (EntityNonScalarPropertiesIndex < 0) { return; } if (EntityNonScalarProperties.Count <= EntityNonScalarPropertiesIndex) { return; } string navigationName = EntityNonScalarProperties[EntityNonScalarPropertiesIndex]; _RefreshCanExecute = true; if (SelectedEntity == null) { return; } if (SelectedEntity.CodeElementRef == null) { return; } CodeClass currentCodeClass = (SelectedEntity.CodeElementRef as CodeClass); CodeProperty codeProperty = currentCodeClass.GetPublicMappedNonScalarPropertyByName(navigationName); if (codeProperty == null) { return; } CodeClass masterCodeClass = codeProperty.Type.CodeType as CodeClass; if (masterCodeClass == null) { return; } masterCodeClassFullName = masterCodeClass.Name; CodeClass dbContext = null; if (SelectedDbContext != null) { if (SelectedDbContext.CodeElementRef != null) { dbContext = SelectedDbContext.CodeElementRef as CodeClass; } } FluentAPIKey primKey = new FluentAPIKey(); masterCodeClass.CollectPrimaryKeyPropsHelper(primKey, dbContext); if (primKey.KeyProperties != null) { int order = 0; primKey.KeyProperties.ForEach(i => i.PropOrder = order++); masterCodeClass.CollectCodeClassAllMappedScalarProperties(PrimaryKeyProperties, primKey.KeyProperties); } List <CodeProperty> masterNavigations = masterCodeClass.GetPublicMappedNonScalarPropertiesByTypeFullName(currentCodeClass.FullName); if (masterNavigations == null) { return; } foreach (CodeProperty masterNavigation in masterNavigations) { PrincipalNonScalarProperties.Add(new FluentAPINavigationProperty() { PropName = masterNavigation.Name, UnderlyingTypeName = currentCodeClass.FullName, FullTypeName = masterNavigation.Type.AsFullName, IsCollection = masterNavigation.IsOfCollectionType() }); } DoRefresh(); }
public override IDatabase Render(string entityName, string ConnectionString) { string CurrentAction = string.Format("Entering Function using {0} and {1}", entityName, ConnectionString); IDatabase schema = this; schema.Name = entityName; try { using (SqlConnection connection = new SqlConnection(ConnectionString)) { if (connection.State == ConnectionState.Closed) { connection.Open(); } using (SqlCommand cmd = new SqlCommand(FKSQL, connection)) { cmd.CommandTimeout = 300; cmd.CommandType = CommandType.Text; var ds = new DataSet(); var adapter = new SqlDataAdapter(cmd); adapter.Fill(ds); var tableColumnData = ds.Tables[0]; var currentSchemaObjectName = ""; var schemaObjectName = ""; IEntity entityType = null; PrimaryKeyProperties primaryKeyList = null; foreach (DataRow row in tableColumnData.Rows) { schemaObjectName = string.Format("{0}.{1}", row["SCHEMANAME"], row["TABLENAME"]); CurrentAction = "Processing " + schemaObjectName; if (currentSchemaObjectName != schemaObjectName) { if (currentSchemaObjectName.Length > 0) { //Temporal views are handled below if ((!entityType.HasPrimaryKeys() && (!entityType.IsTemporalView) && (entityType.TemporalType != "HISTORY_TABLE") && (entityType.Parent.AutoAddPrimaryKeys))) { if (this.ShowWarnings) { Debug.WriteLine("Warning... no primary keys for " + schemaObjectName + ".. adding all as primary keys"); } int order = 0; foreach (var prop in entityType.Properties.Values) { order++; prop.IsKey = true; prop.KeyOrder = order; entityType.PrimaryKeys.Add(prop); } } schema.Add(currentSchemaObjectName, entityType); } entityType = new Entity() { Name = row["TABLENAME"].ToString() , Alias = schemaObjectName , Type = row["OBJECT_TYPE"].ToString() , Schema = row["SCHEMANAME"].ToString() , IsTemporalView = ((schemaObjectName.EndsWith("TemporalView", StringComparison.Ordinal)) && (row["OBJECT_TYPE"].ToString() == "VIEW")) , TemporalType = (row["TEMPORAL_TYPE_DESC"] == DBNull.Value ? "" : row["TEMPORAL_TYPE_DESC"].ToString()) , Parent = schema }; primaryKeyList = new PrimaryKeyProperties(entityType); entityType.PrimaryKeys = primaryKeyList; currentSchemaObjectName = schemaObjectName; } Property property = new Property() { IsNullable = (bool)row["IS_NULLABLE"] }; property.Name = (row["COLUMNNAME"] == DBNull.Value ? "" : row["COLUMNNAME"].ToString()); property.Alias = property.Name + (property.Name.Equals(schemaObjectName) ? "_Text" : ""); property.MaxLength = (int)(row["CHARACTER_MAXIMUM_LENGTH"] == DBNull.Value ? 0 : row["CHARACTER_MAXIMUM_LENGTH"]); property.Precision = (int)(row["NUMERIC_PRECISION"] == DBNull.Value ? 0 : Convert.ToInt32(row["NUMERIC_PRECISION"])); property.Scale = (int)(row["NUMERIC_SCALE"] == DBNull.Value ? 0 : Convert.ToInt32(row["NUMERIC_SCALE"])); property.IsIdentity = (bool)(row["IS_IDENTITY"] == DBNull.Value ? false : row["IS_IDENTITY"]); property.IsKey = (bool)(row["PRIMARY_KEY_ORDER"] == DBNull.Value ? false : true); property.KeyOrder = (int)(row["PRIMARY_KEY_ORDER"] == DBNull.Value ? 0 : Convert.ToInt32(row["PRIMARY_KEY_ORDER"])); if ((entityType.IsTemporalView) && ((property.Name == "SysEndTime") || (property.Name == "SysStartTime"))) { property.IsKey = true; property.KeyOrder = ((property.Name == "SysStartTime") ? 1 : 2); } property.Type = (row["DATA_TYPE"] == DBNull.Value ? "" : row["DATA_TYPE"].ToString()); if (property.IsKey) { entityType.PrimaryKeys.Add(property); } property.Parent = entityType; CurrentAction = string.Format("Adding Property '{0}' to entity '{1}'", property.Name, entityType.Name); entityType.Properties.Add(property.Name, property); } if (currentSchemaObjectName.Length > 0) { //Temporal views are handled abolve if ((!entityType.HasPrimaryKeys() && (!entityType.IsTemporalView) && (entityType.TemporalType != "HISTORY_TABLE"))) { if (ShowWarnings) { Console.WriteLine("Warning... no primary keys for " + currentSchemaObjectName + ".. adding all as primary keys"); } int order = 0; foreach (var prop in entityType.Properties.Values) { order++; prop.IsKey = true; prop.KeyOrder = order; entityType.PrimaryKeys.Add(prop); } } CurrentAction = string.Format("Adding Schema Object {0}", currentSchemaObjectName); schema.Add(currentSchemaObjectName, entityType); } var tableFKeyData = ds.Tables[1]; foreach (DataRow row in tableFKeyData.Rows) { var entityKey = string.Format("{0}.{1}", row["EntitySchema"], row["EntityTable"]); var toEntityKey = string.Format("{0}.{1}", row["RelatedSchema"], row["RelatedTable"]); if (!schema.ContainsKey(entityKey)) { throw new Exception(string.Format("Entity Key {0} was not found.", entityKey)); } var relatedEntityKey = string.Format("{0}.{1}", row["RelatedSchema"], row["RelatedTable"]); if (!schema.ContainsKey(relatedEntityKey)) { throw new Exception(string.Format("Related Entity Key {0} was not found.", relatedEntityKey)); } string fromEntity = (row["EntityTable"] == DBNull.Value ? "" : row["EntityTable"].ToString()); string fromEntityField = (row["EntityColumn"] == DBNull.Value ? "" : row["EntityColumn"].ToString()); string toEntity = (row["RelatedTable"] == DBNull.Value ? "" : row["RelatedTable"].ToString()); string toEntityField = (row["RelatedColumn"] == DBNull.Value ? "" : row["RelatedColumn"].ToString()); string toEntityColumnName = toEntityField.AsFormattedName(); string fromEntityColumnName = fromEntityField.AsFormattedName(); string multiplicity = (row["Multiplicity"] == DBNull.Value ? "" : row["Multiplicity"].ToString()); string primaryTableName = (row["PrimaryTableName"] == DBNull.Value ? "" : row["PrimaryTableName"].ToString()); int ordinalPosition = (row["FKOrdinalPosition"] == DBNull.Value ? 0 : row["FKOrdinalPosition"].AsInt(0)); try { var newRel = new Relationship() { Name = row["FK_Name"] == DBNull.Value ? "" : row["FK_Name"].ToString(), FromTableName = entityKey, FromFieldName = fromEntityField, FromColumnName = fromEntityColumnName, FromEntity = schema[entityKey], FromProperty = schema[entityKey].Properties[fromEntityField], ToFieldName = toEntityField, ToTableName = relatedEntityKey, ToColumnName = toEntityColumnName, ToEntity = schema[toEntityKey], ToProperty = schema[toEntityKey].Properties[toEntityField], Type = multiplicity, PrimaryTableName = primaryTableName, FKOrdinalPosition = ordinalPosition, Parent = schema[entityKey], MultiplicityType = RelationshipMultiplicityType.Unknown }; switch (newRel.Type.ToLower()) { case "one to one": newRel.MultiplicityType = RelationshipMultiplicityType.OneToOne; break; case "one to many": newRel.MultiplicityType = RelationshipMultiplicityType.OneToMany; break; case "zeroorone to many": newRel.MultiplicityType = RelationshipMultiplicityType.ZeroOrOneToMany; break; case "many to one": newRel.MultiplicityType = RelationshipMultiplicityType.ManyToOne; break; case "many to zeroorone": newRel.MultiplicityType = RelationshipMultiplicityType.ManyToZeroOrOne; break; case "one to zeroorone": newRel.MultiplicityType = RelationshipMultiplicityType.OneToZeroOrOne; break; case "zeroorone to one": newRel.MultiplicityType = RelationshipMultiplicityType.ZeroOrOneToOne; break; } CurrentAction = string.Format("Adding Relationships {0} to entity {0}", currentSchemaObjectName, entityKey); schema[entityKey].Relationships.Add(newRel); var fieldToMarkRelation = (entityKey.Equals(newRel.FromTableName) ? newRel.FromFieldName : newRel.ToFieldName); if (schema[entityKey].Properties.ContainsKey(fieldToMarkRelation)) { schema[entityKey].Properties[fieldToMarkRelation].RelatedTo.Add(newRel); } if (string.IsNullOrEmpty(newRel.Name)) { throw new Exception("FK Namne is missing from the relationship"); } if (!schema[entityKey].RelationshipGroups.ContainsKey(newRel.Name)) { schema[entityKey].RelationshipGroups.Add(newRel.Name, new RelationshipList()); } schema[entityKey].RelationshipGroups[newRel.Name].Add(newRel); } catch (Exception relEx) { throw new Exception(string.Format("Error while adding relationship {0}. {1}", row["FK_Name"] == DBNull.Value ? "" : row["FK_Name"].ToString(), relEx.Message ), relEx); } } var tableLastDateTime = ds.Tables[2]; foreach (DataRow row in tableLastDateTime.Rows) { schema.LastUpdates.LastCreated = row["LastCreate"].AsDateTimeNullable(null); schema.LastUpdates.LastModified = row["LastUpdate"].AsDateTimeNullable(null); schema.LastUpdates.LastItemCreated = row["LastItemCreated"].ToSafeString(); schema.LastUpdates.LastItemModified = row["LastItemUpdate"].ToSafeString(); } } var itemCount = schema.Keys.Count(); return(schema); } } catch (Exception ex) { throw new Exception(string.Format("Error While trying to render the database schema. {0} {1} ", CurrentAction, ex.Message), ex); } }