public static PropertyIndexes CalculateIndexes([NotNull] this IEntityType entityType, [NotNull] IPropertyBase propertyBase)
        {
            var index                = 0;
            var shadowIndex          = 0;
            var originalValueIndex   = 0;
            var relationshipIndex    = 0;
            var storeGenerationIndex = 0;

            var baseCounts = entityType.BaseType?.GetCounts();

            if (baseCounts != null)
            {
                index                = baseCounts.PropertyCount;
                shadowIndex          = baseCounts.ShadowCount;
                originalValueIndex   = baseCounts.OriginalValueCount;
                relationshipIndex    = baseCounts.RelationshipCount;
                storeGenerationIndex = baseCounts.StoreGeneratedCount;
            }

            PropertyIndexes callingPropertyIndexes = null;

            foreach (var property in entityType.GetDeclaredProperties())
            {
                var indexes = new PropertyIndexes(
                    index++,
                    property.RequiresOriginalValue() ? originalValueIndex++ : -1,
                    property.IsShadowProperty ? shadowIndex++ : -1,
                    property.IsKeyOrForeignKey() ? relationshipIndex++ : -1,
                    MayBeStoreGenerated(property) ? storeGenerationIndex++ : -1);

                TrySetIndexes(property, indexes);

                if (propertyBase == property)
                {
                    callingPropertyIndexes = indexes;
                }
            }

            foreach (var navigation in entityType.GetDeclaredNavigations())
            {
                var indexes = new PropertyIndexes(index++, -1, -1, relationshipIndex++, -1);

                TrySetIndexes(navigation, indexes);

                if (propertyBase == navigation)
                {
                    callingPropertyIndexes = indexes;
                }
            }

            foreach (var derivedType in entityType.GetDirectlyDerivedTypes())
            {
                derivedType.CalculateIndexes(propertyBase);
            }

            return(callingPropertyIndexes);
        }
        private static void TrySetIndexes(IPropertyBase propertyBase, PropertyIndexes indexes)
        {
            var indexAccessor = propertyBase as IPropertyIndexesAccessor;

            if (indexAccessor != null)
            {
                indexAccessor.PropertyIndexes = indexes;
            }
        }
        /// <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 static PropertyCounts CalculateCounts([NotNull] this IEntityType entityType)
        {
            var index                = 0;
            var navigationIndex      = 0;
            var originalValueIndex   = 0;
            var shadowIndex          = 0;
            var relationshipIndex    = 0;
            var storeGenerationIndex = 0;

            var baseCounts = entityType.BaseType?.GetCounts();

            if (baseCounts != null)
            {
                index                = baseCounts.PropertyCount;
                navigationIndex      = baseCounts.NavigationCount;
                originalValueIndex   = baseCounts.OriginalValueCount;
                shadowIndex          = baseCounts.ShadowCount;
                relationshipIndex    = baseCounts.RelationshipCount;
                storeGenerationIndex = baseCounts.StoreGeneratedCount;
            }

            foreach (var property in entityType.GetDeclaredProperties())
            {
                var indexes = new PropertyIndexes(
                    index: index++,
                    originalValueIndex: property.RequiresOriginalValue() ? originalValueIndex++ : -1,
                    shadowIndex: property.IsShadowProperty ? shadowIndex++ : -1,
                    relationshipIndex: property.IsKeyOrForeignKey() ? relationshipIndex++ : -1,
                    storeGenerationIndex: property.MayBeStoreGenerated() ? storeGenerationIndex++ : -1);

                property.SetIndexes(indexes);
            }

            var isNotifying = entityType.GetChangeTrackingStrategy() != ChangeTrackingStrategy.Snapshot;

            foreach (var navigation in entityType.GetDeclaredNavigations())
            {
                var indexes = new PropertyIndexes(
                    index: navigationIndex++,
                    originalValueIndex: -1,
                    shadowIndex: navigation.IsShadowProperty ? shadowIndex++ : -1,
                    relationshipIndex: navigation.IsCollection() && isNotifying ? -1 : relationshipIndex++,
                    storeGenerationIndex: -1);

                navigation.SetIndexes(indexes);
            }

            return(new PropertyCounts(
                       index,
                       navigationIndex,
                       originalValueIndex,
                       shadowIndex,
                       relationshipIndex,
                       storeGenerationIndex));
        }
Esempio n. 4
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 static void TrySetIndexes([NotNull] this IPropertyBase propertyBase, [CanBeNull] PropertyIndexes indexes)
        {
            var property = propertyBase as IProperty;

            if (property != null)
            {
                property.AsProperty().PropertyIndexes = indexes;
            }
            else
            {
                ((INavigation)propertyBase).AsNavigation().PropertyIndexes = indexes;
            }
        }
Esempio n. 5
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public static void SetIndexes([NotNull] this IPropertyBase propertyBase, [CanBeNull] PropertyIndexes indexes)
 => propertyBase.AsPropertyBase().PropertyIndexes = indexes;
Esempio n. 6
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static PropertyCounts CalculateCounts([NotNull] this EntityType entityType)
        {
            Check.DebugAssert(entityType.Model.IsValidated, "Should not be called on a non-validated model");

            var index                = 0;
            var navigationIndex      = 0;
            var originalValueIndex   = 0;
            var shadowIndex          = 0;
            var relationshipIndex    = 0;
            var storeGenerationIndex = 0;

            var baseCounts = entityType.BaseType?.GetCounts();

            if (baseCounts != null)
            {
                index                = baseCounts.PropertyCount;
                navigationIndex      = baseCounts.NavigationCount;
                originalValueIndex   = baseCounts.OriginalValueCount;
                shadowIndex          = baseCounts.ShadowCount;
                relationshipIndex    = baseCounts.RelationshipCount;
                storeGenerationIndex = baseCounts.StoreGeneratedCount;
            }

            foreach (var property in entityType.GetDeclaredProperties())
            {
                var indexes = new PropertyIndexes(
                    index: index++,
                    originalValueIndex: property.RequiresOriginalValue() ? originalValueIndex++ : -1,
                    shadowIndex: property.IsShadowProperty() ? shadowIndex++ : -1,
                    relationshipIndex: property.IsKey() || property.IsForeignKey() ? relationshipIndex++ : -1,
                    storeGenerationIndex: property.MayBeStoreGenerated() ? storeGenerationIndex++ : -1);

                property.PropertyIndexes = indexes;
            }

            var isNotifying = entityType.GetChangeTrackingStrategy() != ChangeTrackingStrategy.Snapshot;

            foreach (var navigation in entityType.GetDeclaredNavigations()
                     .Union <PropertyBase>(entityType.GetDeclaredSkipNavigations()))
            {
                var indexes = new PropertyIndexes(
                    index: navigationIndex++,
                    originalValueIndex: -1,
                    shadowIndex: navigation.IsShadowProperty() ? shadowIndex++ : -1,
                    relationshipIndex: ((INavigationBase)navigation).IsCollection && isNotifying ? -1 : relationshipIndex++,
                    storeGenerationIndex: -1);

                navigation.PropertyIndexes = indexes;
            }

            foreach (var serviceProperty in entityType.GetDeclaredServiceProperties())
            {
                var indexes = new PropertyIndexes(
                    index: -1,
                    originalValueIndex: -1,
                    shadowIndex: -1,
                    relationshipIndex: -1,
                    storeGenerationIndex: -1);

                serviceProperty.PropertyIndexes = indexes;
            }

            return(new PropertyCounts(
                       index,
                       navigationIndex,
                       originalValueIndex,
                       shadowIndex,
                       relationshipIndex,
                       storeGenerationIndex));
        }
Esempio n. 7
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static PropertyCounts CalculateCounts(this IRuntimeEntityType entityType)
        {
            var index                = 0;
            var navigationIndex      = 0;
            var originalValueIndex   = 0;
            var shadowIndex          = 0;
            var relationshipIndex    = 0;
            var storeGenerationIndex = 0;

            var baseCounts = entityType.BaseType?.GetCounts();

            if (baseCounts != null)
            {
                index                = baseCounts.PropertyCount;
                navigationIndex      = baseCounts.NavigationCount;
                originalValueIndex   = baseCounts.OriginalValueCount;
                shadowIndex          = baseCounts.ShadowCount;
                relationshipIndex    = baseCounts.RelationshipCount;
                storeGenerationIndex = baseCounts.StoreGeneratedCount;
            }

            foreach (var property in entityType.GetDeclaredProperties())
            {
                var indexes = new PropertyIndexes(
                    index: index++,
                    originalValueIndex: property.RequiresOriginalValue() ? originalValueIndex++ : -1,
                    shadowIndex: property.IsShadowProperty() ? shadowIndex++ : -1,
                    relationshipIndex: property.IsKey() || property.IsForeignKey() ? relationshipIndex++ : -1,
                    storeGenerationIndex: property.MayBeStoreGenerated() ? storeGenerationIndex++ : -1);

                ((IRuntimePropertyBase)property).PropertyIndexes = indexes;
            }

            var isNotifying = entityType.GetChangeTrackingStrategy() != ChangeTrackingStrategy.Snapshot;

            foreach (var navigation in entityType.GetDeclaredNavigations()
                     .Union <IPropertyBase>(entityType.GetDeclaredSkipNavigations()))
            {
                var indexes = new PropertyIndexes(
                    index: navigationIndex++,
                    originalValueIndex: -1,
                    shadowIndex: navigation.IsShadowProperty() ? shadowIndex++ : -1,
                    relationshipIndex: ((IReadOnlyNavigationBase)navigation).IsCollection && isNotifying ? -1 : relationshipIndex++,
                    storeGenerationIndex: -1);

                ((IRuntimePropertyBase)navigation).PropertyIndexes = indexes;
            }

            foreach (var serviceProperty in entityType.GetDeclaredServiceProperties())
            {
                var indexes = new PropertyIndexes(
                    index: -1,
                    originalValueIndex: -1,
                    shadowIndex: -1,
                    relationshipIndex: -1,
                    storeGenerationIndex: -1);

                ((IRuntimePropertyBase)serviceProperty).PropertyIndexes = indexes;
            }

            return(new PropertyCounts(
                       index,
                       navigationIndex,
                       originalValueIndex,
                       shadowIndex,
                       relationshipIndex,
                       storeGenerationIndex));
        }
        /// <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 static PropertyIndexes CalculateIndexes([NotNull] this IEntityType entityType, [NotNull] IPropertyBase propertyBase)
        {
            var index = 0;
            var shadowIndex = 0;
            var originalValueIndex = 0;
            var relationshipIndex = 0;
            var storeGenerationIndex = 0;

            var baseCounts = entityType.BaseType?.GetCounts();
            if (baseCounts != null)
            {
                index = baseCounts.PropertyCount;
                shadowIndex = baseCounts.ShadowCount;
                originalValueIndex = baseCounts.OriginalValueCount;
                relationshipIndex = baseCounts.RelationshipCount;
                storeGenerationIndex = baseCounts.StoreGeneratedCount;
            }

            PropertyIndexes callingPropertyIndexes = null;

            foreach (var property in entityType.GetDeclaredProperties())
            {
                var indexes = new PropertyIndexes(
                    index: index++,
                    originalValueIndex: property.RequiresOriginalValue() ? originalValueIndex++ : -1,
                    shadowIndex: property.IsShadowProperty ? shadowIndex++ : -1,
                    relationshipIndex: property.IsKeyOrForeignKey() ? relationshipIndex++ : -1,
                    storeGenerationIndex: property.MayBeStoreGenerated() ? storeGenerationIndex++ : -1);

                TrySetIndexes(property, indexes);

                if (propertyBase == property)
                {
                    callingPropertyIndexes = indexes;
                }
            }

            var isNotifying = entityType.GetChangeTrackingStrategy() != ChangeTrackingStrategy.Snapshot;

            foreach (var navigation in entityType.GetDeclaredNavigations())
            {
                var indexes = new PropertyIndexes(
                    index: index++,
                    originalValueIndex: -1,
                    shadowIndex: -1,
                    relationshipIndex: navigation.IsCollection() && isNotifying ? -1 : relationshipIndex++,
                    storeGenerationIndex: -1);

                TrySetIndexes(navigation, indexes);

                if (propertyBase == navigation)
                {
                    callingPropertyIndexes = indexes;
                }
            }

            foreach (var derivedType in entityType.GetDirectlyDerivedTypes())
            {
                derivedType.CalculateIndexes(propertyBase);
            }

            return callingPropertyIndexes;
        }
 private static void TrySetIndexes(IPropertyBase propertyBase, PropertyIndexes indexes)
     => propertyBase.AsPropertyBase().PropertyIndexes = indexes;
 private static void TrySetIndexes(IPropertyBase propertyBase, PropertyIndexes indexes)
 => propertyBase.AsPropertyBase().PropertyIndexes = indexes;