public static void AddAnnotation(this MetadataCli.EntityType entityType, string key, object value)
 {
     if (entityType.Annotations == null)
     {
         entityType.Annotations = new Dictionary <string, object>();
     }
     entityType.Annotations.Add(key, value);
 }
        public static void AddAnnotation(MetadataCli.EntityType entityTypeLocal, string navigationPropertyNameLocal, MetadataCli.EntityType entityTypeRemote, string navigationPropertyNameRemote)
        {
            var navigationPropertyLocal  = entityTypeLocal.NavigationProperties[navigationPropertyNameLocal];
            var navigationPropertyRemote = entityTypeRemote.NavigationProperties[navigationPropertyNameRemote];

            if (!(navigationPropertyLocal.KeyLocal.SequenceEqual(navigationPropertyRemote.KeyRemote) && navigationPropertyLocal.KeyRemote.SequenceEqual(navigationPropertyRemote.KeyLocal)))
            {
                throw new ArgumentException("The two navigation properties are not pairs");
            }

            var idGroupLocal  = (entityTypeLocal.Annotations != null && entityTypeLocal.Annotations.ContainsKey("IdGroup")) ? (int)entityTypeLocal.Annotations["IdGroup"] : default(int?);
            var idGroupRemote = (entityTypeRemote.Annotations != null && entityTypeRemote.Annotations.ContainsKey("IdGroup")) ? (int)entityTypeRemote.Annotations["IdGroup"] : default(int?);

            if (idGroupLocal != null || idGroupRemote != null)
            {
                if (idGroupLocal != idGroupRemote)
                {
                    if (idGroupLocal != null)
                    {
                        if (navigationPropertyRemote.Annotations == null)
                        {
                            navigationPropertyRemote.Annotations = new Dictionary <string, object>();
                        }
                        if (entityTypeLocal.Annotations.ContainsKey("IsVirtual"))
                        {
                            navigationPropertyRemote.Annotations.Add("IsVirtual", entityTypeLocal.Annotations["IsVirtual"]);
                        }
                        navigationPropertyRemote.Annotations.Add("IdGroup", idGroupLocal);
                    }

                    if (idGroupRemote != null)
                    {
                        if (navigationPropertyLocal.Annotations == null)
                        {
                            navigationPropertyLocal.Annotations = new Dictionary <string, object>();
                        }
                        if (entityTypeRemote.Annotations.ContainsKey("IsVirtual"))
                        {
                            navigationPropertyLocal.Annotations.Add("IsVirtual", entityTypeRemote.Annotations["IsVirtual"]);
                        }
                        navigationPropertyLocal.Annotations.Add("IdGroup", idGroupRemote);
                    }
                }
            }
        }