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.Indexes = indexes; } }