Пример #1
0
        private static QueryResultScope <TEntity> CreateEntity <TEntity>(
            IQuerySource querySource,
            QueryContext queryContext,
            QueryResultScope parentQueryResultScope,
            ValueBuffer valueBuffer,
            int valueBufferOffset,
            IEntityType entityType,
            bool queryStateManager,
            EntityKeyFactory entityKeyFactory,
            IReadOnlyList <IProperty> keyProperties,
            Func <ValueBuffer, object> materializer)
            where TEntity : class
        {
            valueBuffer = valueBuffer.WithOffset(valueBufferOffset);

            var entityKey
                = entityKeyFactory.Create(keyProperties, valueBuffer);

            return(new QueryResultScope <TEntity>(
                       querySource,
                       entityKey != EntityKey.InvalidEntityKey
                    ? (TEntity)queryContext.QueryBuffer
                       .GetEntity(
                           entityType,
                           entityKey,
                           new EntityLoadInfo(
                               valueBuffer,
                               materializer),
                           queryStateManager)
                    : null,
                       parentQueryResultScope));
        }
Пример #2
0
        private object GetTargetEntity(
            IEntityType targetEntityType,
            EntityKeyFactory entityKeyFactory,
            IReadOnlyList <IProperty> keyProperties,
            EntityLoadInfo entityLoadInfo,
            ICollection <BufferedEntity> bufferedEntities,
            bool querySourceRequiresTracking)
        {
            var entityKey
                = entityKeyFactory
                  .Create(targetEntityType, keyProperties, entityLoadInfo.ValueReader);

            var targetEntity
                = GetEntity(
                      targetEntityType,
                      entityKey,
                      entityLoadInfo,
                      querySourceRequiresTracking);

            if (targetEntity != null)
            {
                List <BufferedEntity> bufferedTargetEntities;
                bufferedEntities.Add(
                    _byEntityInstance.TryGetValue(targetEntity, out bufferedTargetEntities)
                        ? bufferedTargetEntities[0]
                        : new BufferedEntity(targetEntityType, entityLoadInfo.ValueReader)
                {
                    Instance = targetEntity
                });
            }

            return(targetEntity);
        }
Пример #3
0
            public IncludedEntityTrackingInfo(
                [NotNull] IEntityType entityType,
                [NotNull] EntityKeyFactory entityKeyFactory,
                [NotNull] IReadOnlyList <IProperty> entityKeyProperties)
            {
                Check.NotNull(entityType, nameof(entityType));
                Check.NotNull(entityKeyFactory, nameof(entityKeyFactory));
                Check.NotNull(entityKeyProperties, nameof(entityKeyProperties));

                EntityType          = entityType;
                EntityKeyFactory    = entityKeyFactory;
                EntityKeyProperties = entityKeyProperties;
            }
Пример #4
0
        public EntityTrackingInfo(
            [NotNull] IEntityKeyFactorySource entityKeyFactorySource,
            [NotNull] IClrAccessorSource <IClrPropertyGetter> clrPropertyGetterSource,
            [NotNull] QueryCompilationContext queryCompilationContext,
            [NotNull] QuerySourceReferenceExpression querySourceReferenceExpression,
            [NotNull] IEntityType entityType)
        {
            Check.NotNull(entityKeyFactorySource, nameof(entityKeyFactorySource));
            Check.NotNull(clrPropertyGetterSource, nameof(clrPropertyGetterSource));
            Check.NotNull(querySourceReferenceExpression, nameof(querySourceReferenceExpression));
            Check.NotNull(entityType, nameof(entityType));
            Check.NotNull(queryCompilationContext, nameof(queryCompilationContext));

            QuerySourceReferenceExpression = querySourceReferenceExpression;

            _entityType = entityType;
            _queryCompilationContext = queryCompilationContext;
            _entityKeyFactorySource  = entityKeyFactorySource;
            _clrPropertyGetterSource = clrPropertyGetterSource;

            _entityKeyProperties = _entityType.GetPrimaryKey().Properties;

            _entityKeyFactory = _entityKeyFactorySource.GetKeyFactory(_entityType.GetPrimaryKey());

            _includedNavigationPaths
                = _queryCompilationContext
                  .GetTrackableIncludes(querySourceReferenceExpression.ReferencedQuerySource);

            if (_includedNavigationPaths != null)
            {
                _includedEntityTrackingInfos = new Dictionary <INavigation, IncludedEntityTrackingInfo>();

                foreach (var navigation
                         in _includedNavigationPaths.SelectMany(ns => ns))
                {
                    if (!_includedEntityTrackingInfos.ContainsKey(navigation))
                    {
                        var targetEntityType = navigation.GetTargetType();
                        var targetKey        = targetEntityType.GetPrimaryKey();

                        _includedEntityTrackingInfos.Add(
                            navigation,
                            new IncludedEntityTrackingInfo(
                                targetEntityType,
                                _entityKeyFactorySource.GetKeyFactory(targetKey),
                                targetKey.Properties));
                    }
                }
            }
        }
        private static QueryResultScope <TEntity> CreateEntity <TEntity>(
            IQuerySource querySource,
            QueryContext queryContext,
            QueryResultScope parentQueryResultScope,
            ValueBuffer valueBuffer,
            int valueBufferOffset,
            IEntityType entityType,
            bool queryStateManager,
            EntityKeyFactory entityKeyFactory,
            IReadOnlyList <IProperty> keyProperties,
            Func <ValueBuffer, object> materializer,
            bool allowNullResult)
            where TEntity : class
        {
            valueBuffer = valueBuffer.WithOffset(valueBufferOffset);

            var entityKey
                = entityKeyFactory.Create(keyProperties, valueBuffer);

            TEntity entity = null;

            if (entityKey == EntityKey.InvalidEntityKey)
            {
                if (!allowNullResult)
                {
                    throw new InvalidOperationException(RelationalStrings.InvalidKeyValue(entityType.DisplayName()));
                }
            }
            else
            {
                entity
                    = (TEntity)queryContext.QueryBuffer
                      .GetEntity(
                          entityType,
                          entityKey,
                          new EntityLoadInfo(valueBuffer, materializer),
                          queryStateManager);
            }

            return(new QueryResultScope <TEntity>(querySource, entity, parentQueryResultScope));
        }
        private static QuerySourceScope <TEntity> CreateEntity <TEntity>(
            IQuerySource querySource,
            QueryContext queryContext,
            QuerySourceScope parentQuerySourceScope,
            DbDataReader dataReader,
            int readerOffset,
            IEntityType entityType,
            bool queryStateManager,
            EntityKeyFactory entityKeyFactory,
            IReadOnlyList <IProperty> keyProperties,
            Func <IValueReader, object> materializer)
            where TEntity : class
        {
            var valueReader
                = ((RelationalQueryContext)queryContext).ValueReaderFactory
                  .Create(dataReader);

            if (readerOffset > 0)
            {
                valueReader = new OffsetValueReaderDecorator(valueReader, readerOffset);
            }

            var entityKey
                = entityKeyFactory.Create(entityType, keyProperties, valueReader);

            return(new QuerySourceScope <TEntity>(
                       querySource,
                       (TEntity)queryContext.QueryBuffer
                       .GetEntity(
                           entityType,
                           entityKey,
                           new EntityLoadInfo(
                               valueReader,
                               materializer),
                           queryStateManager),
                       parentQuerySourceScope));
        }
Пример #7
0
 public virtual EntityKey CreateEntityKey(ValueBuffer valueBuffer)
 => EntityKeyFactory.Create(EntityKeyProperties, valueBuffer);
Пример #8
0
 public virtual EntityKey CreateEntityKey(ValueBuffer valueBuffer)
 {
     return(EntityKeyFactory.Create(EntityType, EntityKeyProperties, valueBuffer));
 }