예제 #1
0
        private async Task IncludeAsync(
            object entity,
            IReadOnlyList <INavigation> navigationPath,
            IReadOnlyList <AsyncRelatedEntitiesLoader> relatedEntitiesLoaders,
            CancellationToken cancellationToken,
            int currentNavigationIndex,
            bool queryStateManager)
        {
            if (entity == null ||
                currentNavigationIndex == navigationPath.Count)
            {
                return;
            }

            var navigation  = navigationPath[currentNavigationIndex];
            var keyComparer = IncludeCore(entity, navigation);
            var key         = navigation.GetTargetType().FindPrimaryKey();

            LoadNavigationProperties(
                entity,
                navigationPath,
                currentNavigationIndex,
                await AsyncEnumerableExtensions.Select(relatedEntitiesLoaders[currentNavigationIndex](keyComparer), async(eli, ct) =>
            {
                var targetEntity = GetEntity(key, eli, queryStateManager, throwOnNullKey: false);

                await IncludeAsync(
                    targetEntity,
                    navigationPath,
                    relatedEntitiesLoaders,
                    ct,
                    currentNavigationIndex + 1,
                    queryStateManager);

                return(targetEntity);
            })
                .Where(e => e != null)
                .ToList(cancellationToken));
        }
예제 #2
0
        private async Task IncludeAsync(
            object entity,
            IReadOnlyList <INavigation> navigationPath,
            IReadOnlyList <AsyncRelatedEntitiesLoader> relatedEntitiesLoaders,
            CancellationToken cancellationToken,
            int currentNavigationIndex,
            bool queryStateManager)
        {
            if (entity == null ||
                currentNavigationIndex == navigationPath.Count)
            {
                return;
            }

            EntityKey primaryKey;
            Func <ValueBuffer, EntityKey> relatedKeyFactory;

            var targetEntityType
                = IncludeCore(
                      entity,
                      navigationPath[currentNavigationIndex],
                      out primaryKey,
                      out relatedKeyFactory);

            var keyProperties
                = targetEntityType.GetPrimaryKey().Properties;

            var entityKeyFactory
                = _entityKeyFactorySource
                  .GetKeyFactory(targetEntityType.GetPrimaryKey());

            LoadNavigationProperties(
                entity,
                navigationPath,
                currentNavigationIndex,
                await AsyncEnumerableExtensions.Select(relatedEntitiesLoaders[currentNavigationIndex](primaryKey, relatedKeyFactory), async(eli, ct) =>
            {
                var entityKey
                    = entityKeyFactory
                      .Create(keyProperties, eli.ValueBuffer);

                object targetEntity = null;

                if (entityKey != EntityKey.InvalidEntityKey)
                {
                    targetEntity
                        = GetEntity(
                              targetEntityType,
                              entityKey,
                              eli,
                              queryStateManager);
                }

                await IncludeAsync(
                    targetEntity,
                    navigationPath,
                    relatedEntitiesLoaders,
                    ct,
                    currentNavigationIndex + 1,
                    queryStateManager);

                return(targetEntity);
            })
                .Where(e => e != null)
                .ToList(cancellationToken));
        }