public void DoRefresh() { if (EntityNonScalarPropertiesIndex < 0) { return; } if (EntityNonScalarProperties.Count <= EntityNonScalarPropertiesIndex) { return; } if (SelectedEntity == null) { return; } if (SelectedEntity.CodeElementRef == null) { return; } string navigationName = EntityNonScalarProperties[EntityNonScalarPropertiesIndex]; CodeClass dbContext = null; if (SelectedDbContext != null) { if (SelectedDbContext.CodeElementRef != null) { dbContext = SelectedDbContext.CodeElementRef as CodeClass; } } List <FluentAPIForeignKey> frnKeys = (SelectedEntity.CodeElementRef as CodeClass).CollectForeignKeys(dbContext, new List <string> { navigationName }); if (frnKeys == null) { ErrorsText = "No Fk detected"; return; } if (frnKeys.Count < 1) { ErrorsText = "No Fk detected"; return; } string className = (SelectedEntity.CodeElementRef as CodeClass).Name; if (frnKeys[0].HasErrors) { ErrorsText = frnKeys[0].ErrorsText; } else { ErrorsText = null; } IsCascadeOnDelete = frnKeys[0].IsCascadeDelete; if (frnKeys[0].EntityName == className) { string navName = frnKeys[0].InverseNavigationName; if (PrincipalNonScalarProperties != null) { FluentAPINavigationProperty np = PrincipalNonScalarProperties.FirstOrDefault(p => p.PropName == navName); if (np != null) { PrincipalNonScalarPropertiesIndex = PrincipalNonScalarProperties.IndexOf(np); } else { PrincipalNonScalarPropertiesIndex = -1; } } ForeignKeyProperties.Clear(); if ((frnKeys[0].ForeignKeyProps != null) && (EntityProperties != null)) { foreach (FluentAPIProperty itm in frnKeys[0].ForeignKeyProps) { FluentAPIExtendedProperty currItm = EntityProperties.FirstOrDefault(i => i.PropName == itm.PropName); if (currItm != null) { ForeignKeyProperties.Add(currItm); } } } ForeignKeyTypesIndex = ForeignKeyTypes.IndexOf(frnKeys[0].NavigationType); } else { PrincipalNonScalarPropertiesIndex = -1; ForeignKeyProperties.Clear(); } }
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(); }