public virtual void DoAnalize() { HasPrimKey = false; SelectedProppertyName = ""; ActionUserControl = null; if (SelectedDbContext != null) { if (SelectedDbContext.CodeElementRef != null) { if (SelectedCodeElement != null) { if (SelectedCodeElement.CodeElementRef != null) { SelectedProppertyName = (SelectedDbContext.CodeElementRef as CodeClass).GetDbContextDbSetPropertyNameHelper(SelectedCodeElement.CodeElementName, SelectedCodeElement.CodeElementFullName); if (string.IsNullOrEmpty(SelectedProppertyName)) { if (_ActionUserControl == null) { _ActionUserControl = new UserControlOneCommand(this); } UiCommandProppertyName = SelectedCodeElement.CodeElementName + UiCommandProppertySufix; DefineUiCaptions(); ActionUserControl = _ActionUserControl; } else { // Primary key analize here FluentAPIKey primKey = new FluentAPIKey(); (SelectedCodeElement.CodeElementRef as CodeClass).CollectPrimaryKeyPropsHelper(primKey, SelectedDbContext.CodeElementRef as CodeClass); if (primKey.KeyProperties != null) { HasPrimKey = primKey.KeyProperties.Count > 0; } if (_PrimKeyUserControl == null) { _PrimKeyUserControl = new UserControlOneCommand(this); } ReDefineUiCaptions(primKey); ActionUserControl = _PrimKeyUserControl; } } } } } OnPropertyChanged("ActionUserControl"); OnPropertyChanged("SelectedProppertyName"); CheckIsReady(); }
public void ReDefineUiCaptions(FluentAPIKey primKey) { if (HasPrimKey) { UiCommandCaption1 = "A Prim.Key was found for the selected Entity. Detection type [" + primKey.KeySourceDisplay + "]"; UiCommandCaption2 = "Key Fileds ["; foreach (FluentAPIProperty pp in primKey.KeyProperties) { UiCommandCaption2 = UiCommandCaption2 + " " + pp.PropName; } UiCommandCaption2 += " ]"; if (primKey.SourceCount > 1) { UiCommandCaption3 = "The setting had met more than once: " + primKey.SourceCount.ToString() + " !!!!"; } else { UiCommandCaption3 = null; } UiCommandCaption2BackGround = 10 + (int)primKey.KeySource; } else { UiCommandCaption2BackGround = 9; UiCommandCaption1 = "A Primary Key was not found for the selected Entity"; UiCommandCaption2 = "It is recommended to make the primary key settings in OnModelCreating(...)-method"; UiCommandCaption3 = null; } UiCommandLabelCaption = " Add/Modify Primaky Key setting in OnModelCreating(...)-method "; UiCommandButtonCaption = " Modify "; UiCommandProppertyNameVisibility = Visibility.Collapsed; OnPropertyChanged("UiCommandProppertySufix"); OnPropertyChanged("UiCommandCaption1"); OnPropertyChanged("UiCommandCaption2"); OnPropertyChanged("UiCommandCaption3"); OnPropertyChanged("UiCommandLabelCaption"); OnPropertyChanged("UiCommandButtonCaption"); OnPropertyChanged("UiCommandProppertyNameVisibility"); OnPropertyChanged("UiCommandCaption2BackGround"); // we had to define UiCommandProppertyName for UiBtnCommandCanExecute() has to return true UiCommandProppertyName = "NoName"; }
public void CollectPrimaryKeyProperties() { PrimaryKeyPropertiesIndex = -1; PrimaryKeyProperties.Clear(); if (SelectedEntity != null) { if (SelectedEntity.CodeElementRef != null) { if (SelectedDbContext != null) { if (SelectedDbContext.CodeElementRef != null) { FluentAPIKey primKey = new FluentAPIKey(); (SelectedEntity.CodeElementRef as CodeClass).CollectPrimaryKeyPropsHelper(primKey, SelectedDbContext.CodeElementRef as CodeClass); if ((primKey.KeyProperties != null) && (EntityProperties != null)) { int order = 0; primKey.KeyProperties.ForEach(i => i.PropOrder = order++); (SelectedEntity.CodeElementRef as CodeClass).CollectCodeClassAllMappedScalarProperties(PrimaryKeyProperties, primKey.KeyProperties); //foreach (FluentAPIProperty itm in primKey.KeyProperties) //{ // FluentAPIExtendedProperty primKeyProp = EntityProperties.FirstOrDefault(e => e.PropName == itm.PropName); // if (primKeyProp != null) // { // PrimaryKeyProperties.Add(primKeyProp); // } else // { // PrimaryKeyProperties.Add( // new FluentAPIExtendedProperty() // { // PropName = itm.PropName // }); // } //} } } } } } OnPropertyChanged("PrimaryKeyProperties"); }
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(); }