public void OnPrincipalNonScalarPropertiesIndexChanged()
 {
     if ((PrincipalNonScalarPropertiesIndex < 0) || (PrincipalNonScalarPropertiesIndex >= PrincipalNonScalarProperties.Count))
     {
         ForeignKeyTypesIndex = -1;
         ForeignKeyTypes.Clear();
         ForeignKeyTypes.Add(NavigationTypeEnum.Unckown);
         return;
     }
     if (PrincipalNonScalarProperties[PrincipalNonScalarPropertiesIndex].IsCollection)
     {
         if (ForeignKeyTypes.Count == 3)
         {
             if (ForeignKeyTypes.IndexOf(NavigationTypeEnum.OptionalToMany) > -1)
             {
                 return;
             }
         }
         ForeignKeyTypesIndex = -1;
         ForeignKeyTypes.Clear();
         ForeignKeyTypes.Add(NavigationTypeEnum.Unckown);
         ForeignKeyTypes.Add(NavigationTypeEnum.OneToMany);
         ForeignKeyTypes.Add(NavigationTypeEnum.OptionalToMany);
     }
     else
     {
         if (ForeignKeyTypes.Count == 3)
         {
             if (ForeignKeyTypes.IndexOf(NavigationTypeEnum.OneToOne) > -1)
             {
                 return;
             }
         }
         ForeignKeyTypesIndex = -1;
         ForeignKeyTypes.Clear();
         ForeignKeyTypes.Add(NavigationTypeEnum.OneToOne);
         ForeignKeyTypes.Add(NavigationTypeEnum.OptionalToOne);
     }
 }
        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();
            }
        }