Exemplo n.º 1
0
 private void SetNavigation(InternalEntityEntry entry, INavigation navigation, object value)
 {
     if (navigation != null)
     {
         _changeDetector.Suspend();
         try
         {
             entry[navigation] = value;
         }
         finally
         {
             _changeDetector.Resume();
         }
         entry.SetRelationshipSnapshotValue(navigation, value);
     }
 }
Exemplo n.º 2
0
 private void SetNavigation(InternalEntityEntry entry, INavigation navigation, InternalEntityEntry value)
 {
     if (navigation != null)
     {
         _changeDetector.Suspend();
         var entity = value?.Entity;
         try
         {
             entry[navigation] = entity;
         }
         finally
         {
             _changeDetector.Resume();
         }
         entry.SetRelationshipSnapshotValue(navigation, entity);
     }
 }
Exemplo n.º 3
0
 private void AddToCollection(InternalEntityEntry entry, INavigation navigation, InternalEntityEntry value)
 {
     if (navigation != null)
     {
         _changeDetector.Suspend();
         try
         {
             if (entry.AddToCollection(navigation, value))
             {
                 entry.AddToCollectionSnapshot(navigation, value.Entity);
             }
         }
         finally
         {
             _changeDetector.Resume();
         }
     }
 }
Exemplo n.º 4
0
 private void SetNavigation(IClrPropertySetter setter, object entity, object value)
 {
     _changeDetector.Suspend();
     try
     {
         setter.SetClrValue(entity, value);
     }
     finally
     {
         _changeDetector.Resume();
     }
 }
Exemplo n.º 5
0
        private void LoadNavigationProperties(
            object entity,
            IReadOnlyList <INavigation> navigationPath,
            int currentNavigationIndex,
            IReadOnlyList <object> relatedEntities)
        {
            _changeDetector.Suspend();
            try
            {
                if (navigationPath[currentNavigationIndex].IsDependentToPrincipal() &&
                    relatedEntities.Any())
                {
                    navigationPath[currentNavigationIndex]
                    .GetSetter()
                    .SetClrValue(entity, relatedEntities[0]);

                    var inverseNavigation = navigationPath[currentNavigationIndex].FindInverse();

                    if (inverseNavigation != null)
                    {
                        if (inverseNavigation.IsCollection())
                        {
                            inverseNavigation
                            .GetCollectionAccessor()
                            .AddRange(relatedEntities[0], new[] { entity });
                        }
                        else
                        {
                            inverseNavigation
                            .GetSetter()
                            .SetClrValue(relatedEntities[0], entity);
                        }
                    }
                }
                else
                {
                    if (navigationPath[currentNavigationIndex].IsCollection())
                    {
                        navigationPath[currentNavigationIndex]
                        .GetCollectionAccessor()
                        .AddRange(entity, relatedEntities);

                        var inverseNavigation = navigationPath[currentNavigationIndex].FindInverse();

                        if (inverseNavigation != null)
                        {
                            var clrPropertySetter
                                = inverseNavigation.GetSetter();

                            foreach (var relatedEntity in relatedEntities)
                            {
                                clrPropertySetter.SetClrValue(relatedEntity, entity);
                            }
                        }
                    }
                    else if (relatedEntities.Any())
                    {
                        navigationPath[currentNavigationIndex]
                        .GetSetter()
                        .SetClrValue(entity, relatedEntities[0]);

                        var inverseNavigation = navigationPath[currentNavigationIndex].FindInverse();

                        inverseNavigation?.GetSetter()
                        .SetClrValue(relatedEntities[0], entity);
                    }
                }
            }
            finally
            {
                _changeDetector.Resume();
            }
        }
Exemplo n.º 6
0
        private void LoadNavigationProperties(
            object entity,
            IReadOnlyList <INavigation> navigationPath,
            int currentNavigationIndex,
            IReadOnlyList <object> relatedEntities,
            bool tracking)
        {
            _changeDetector.Suspend();
            try
            {
                var navigation        = navigationPath[currentNavigationIndex];
                var inverseNavigation = navigation.FindInverse();

                if (navigation.IsDependentToPrincipal() &&
                    relatedEntities.Any())
                {
                    var relatedEntity = relatedEntities[0];

                    SetNavigation(entity, navigation, relatedEntity, tracking);

                    if (inverseNavigation != null)
                    {
                        if (inverseNavigation.IsCollection())
                        {
                            AddToCollection(relatedEntity, inverseNavigation, entity, tracking);
                        }
                        else
                        {
                            SetNavigation(relatedEntity, inverseNavigation, entity, tracking);
                        }
                    }
                }
                else
                {
                    if (navigation.IsCollection())
                    {
                        AddRangeToCollection(entity, navigation, relatedEntities, tracking);

                        if (inverseNavigation != null)
                        {
                            var setter = inverseNavigation.GetSetter();

                            foreach (var relatedEntity in relatedEntities)
                            {
                                SetNavigation(relatedEntity, inverseNavigation, setter, entity, tracking);
                            }
                        }
                    }
                    else if (relatedEntities.Any())
                    {
                        var relatedEntity = relatedEntities[0];

                        SetNavigation(entity, navigation, relatedEntity, tracking);

                        if (inverseNavigation != null)
                        {
                            SetNavigation(relatedEntity, inverseNavigation, entity, tracking);
                        }
                    }
                }
            }
            finally
            {
                _changeDetector.Resume();
            }
        }