Ejemplo n.º 1
0
 /// <summary>
 ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
 ///     directly from your code. This API may change or be removed in future releases.
 /// </summary>
 public virtual Navigation HasPrincipalToDependent(
     [CanBeNull] PropertyInfo property,
     // ReSharper disable once MethodOverloadWithOptionalParameter
     ConfigurationSource configurationSource = ConfigurationSource.Explicit)
 => Navigation(PropertyIdentity.Create(property), configurationSource, pointsToPrincipal: false);
Ejemplo n.º 2
0
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used 
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        private Navigation Navigation(
            PropertyIdentity? propertyIdentity,
            ConfigurationSource configurationSource,
            bool runConventions,
            bool pointsToPrincipal)
        {
            var name = propertyIdentity?.Name;
            var oldNavigation = pointsToPrincipal ? DependentToPrincipal : PrincipalToDependent;
            if (name == oldNavigation?.Name)
            {
                if (pointsToPrincipal)
                {
                    UpdateDependentToPrincipalConfigurationSource(configurationSource);
                }
                else
                {
                    UpdatePrincipalToDependentConfigurationSource(configurationSource);
                }
                return oldNavigation;
            }

            if (oldNavigation != null)
            {
                Debug.Assert(oldNavigation.Name != null);
                if (pointsToPrincipal)
                {
                    DeclaringEntityType.RemoveNavigation(oldNavigation.Name);
                }
                else
                {
                    PrincipalEntityType.RemoveNavigation(oldNavigation.Name);
                }
            }

            Navigation navigation = null;
            var property = propertyIdentity?.Property;
            if (property != null)
            {
                navigation = pointsToPrincipal
                    ? DeclaringEntityType.AddNavigation(property, this, pointsToPrincipal: true)
                    : PrincipalEntityType.AddNavigation(property, this, pointsToPrincipal: false);
            }
            else if (name != null)
            {
                navigation = pointsToPrincipal
                    ? DeclaringEntityType.AddNavigation(name, this, pointsToPrincipal: true)
                    : PrincipalEntityType.AddNavigation(name, this, pointsToPrincipal: false);
            }

            if (pointsToPrincipal)
            {
                DependentToPrincipal = navigation;
                UpdateDependentToPrincipalConfigurationSource(configurationSource);
            }
            else
            {
                PrincipalToDependent = navigation;
                UpdatePrincipalToDependentConfigurationSource(configurationSource);
            }

            if (runConventions)
            {
                if (oldNavigation != null)
                {
                    Debug.Assert(oldNavigation.Name != null);

                    if (pointsToPrincipal)
                    {
                        DeclaringEntityType.Model.ConventionDispatcher.OnNavigationRemoved(
                            DeclaringEntityType.Builder,
                            PrincipalEntityType.Builder,
                            oldNavigation.Name,
                            oldNavigation.PropertyInfo);
                    }
                    else
                    {
                        DeclaringEntityType.Model.ConventionDispatcher.OnNavigationRemoved(
                            PrincipalEntityType.Builder,
                            DeclaringEntityType.Builder,
                            oldNavigation.Name,
                            oldNavigation.PropertyInfo);
                    }
                }

                if (navigation != null)
                {
                    var builder = DeclaringEntityType.Model.ConventionDispatcher.OnNavigationAdded(Builder, navigation);
                    navigation = pointsToPrincipal ? builder?.Metadata.DependentToPrincipal : builder?.Metadata.PrincipalToDependent;
                }
            }

            return navigation ?? oldNavigation;
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
 ///     directly from your code. This API may change or be removed in future releases.
 /// </summary>
 public virtual Navigation HasDependentToPrincipal(
     [CanBeNull] string name,
     // ReSharper disable once MethodOverloadWithOptionalParameter
     ConfigurationSource configurationSource = ConfigurationSource.Explicit)
 => Navigation(PropertyIdentity.Create(name), configurationSource, pointsToPrincipal: true);