Ejemplo n.º 1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="EntityLoadInfo"/> struct.
        /// </summary>
        /// <param name="valueBuffer"> The row of data that represents this entity. </param>
        /// <param name="materializer"> The method to materialize the data into an entity instance. </param>
        public EntityLoadInfo(
            ValueBuffer valueBuffer, [NotNull] Func<ValueBuffer, object> materializer)
        {
            // hot path
            Debug.Assert(materializer != null);

            ValueBuffer = valueBuffer;
            _materializer = materializer;
        }
        public object CreateEntity(ValueBuffer valueBuffer)
        {
            DbContext context = (DbContext) valueBuffer[valueBuffer.Count - 1];
            if (_proxyBuilder == null)
            {
                _proxyBuilder = context.GetInfrastructure().GetService<IProxyBuilder>();
            }

            return _proxyBuilder.ConstructProxy(this, valueBuffer, context);
        }
 public override InternalEntityEntry StartTrackingFromQuery(IEntityType entityType, object entity, ValueBuffer valueBuffer)
 {
     InTracking = true;
     try
     {
         return base.StartTrackingFromQuery(entityType, entity, valueBuffer);
     }
     finally
     {
         InTracking = false;
     }
 }
Ejemplo n.º 4
0
        public void StartTracking_is_no_op_if_entity_is_already_tracked()
        {
            var model = BuildModel();
            var categoryType = model.FindEntityType(typeof(Category));
            var stateManager = CreateStateManager(model);

            var category = new Category { Id = 77, PrincipalId = 777 };
            var valueBuffer = new ValueBuffer(new object[] { 77, "Bjork", 777 });

            var entry = stateManager.StartTrackingFromQuery(categoryType, category, valueBuffer);

            Assert.Same(entry, stateManager.StartTrackingFromQuery(categoryType, category, valueBuffer));
        }
        private static InternalEntityEntry NewInternalEntityEntry(
            IStateManager stateManager,
            IEntityType entityType,
            object entity,
            ValueBuffer valueBuffer)
        {
            if (!entityType.HasClrType())
            {
                return new InternalShadowEntityEntry(stateManager, entityType, valueBuffer);
            }

            return entityType.ShadowPropertyCount() > 0
                ? (InternalEntityEntry)new InternalMixedEntityEntry(stateManager, entityType, entity, valueBuffer)
                : new InternalClrEntityEntry(stateManager, entityType, entity);
        }
Ejemplo n.º 6
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 virtual void StartTracking(
            [NotNull] IStateManager stateManager, [NotNull] object entity, ValueBuffer valueBuffer)
        {
            Check.NotNull(stateManager, nameof(stateManager));
            Check.NotNull(entity, nameof(entity));

            stateManager.StartTrackingFromQuery(_entityType, entity, valueBuffer);
        }
Ejemplo n.º 7
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 void StartTracking([NotNull] IStateManager stateManager, ValueBuffer valueBuffer)
            {
                Check.NotNull(stateManager, nameof(stateManager));

                stateManager.StartTrackingFromQuery(
                    EntityType,
                    Entity,
                    valueBuffer);
            }
Ejemplo n.º 8
0
 private bool Equals(ValueBuffer other)
     => Equals(_values, other._values)
        && _offset == other._offset;
        public virtual void PropagateResults(ValueBuffer valueBuffer)
        {
            Check.NotNull(valueBuffer, nameof(valueBuffer));

            // Note that this call sets the value into a sidecar and will only commit to the actual entity
            // if SaveChanges is successful.
            var index = 0;
            foreach (var modification in ColumnModifications.Where(o => o.IsRead))
            {
                modification.Value = valueBuffer[index++];
            }
        }
 public MaterializationContext(ValueBuffer valueBuffer)
 {
     ValueBuffer = valueBuffer;
     Context     = null;
 }
Ejemplo n.º 11
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 virtual InternalEntityEntry TryGetEntry(IKey key, ValueBuffer valueBuffer, bool throwOnNullKey)
     => GetOrCreateIdentityMap(key).TryGetEntry(valueBuffer, throwOnNullKey);
Ejemplo n.º 12
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 virtual InternalEntityEntry StartTrackingFromQuery(
            IEntityType baseEntityType,
            object entity,
            ValueBuffer valueBuffer)
        {
            var existingEntry = TryGetEntry(entity);
            if (existingEntry != null)
            {
                return existingEntry;
            }

            var clrType = entity.GetType();

            var newEntry = _factory.Create(this,
                baseEntityType.ClrType == clrType
                    ? baseEntityType
                    : _model.FindEntityType(clrType),
                entity, valueBuffer);

            foreach (var key in baseEntityType.GetKeys())
            {
                GetOrCreateIdentityMap(key).AddOrUpdate(newEntry);
            }

            _entityReferenceMap[entity] = newEntry;

            newEntry.MarkUnchangedFromQuery();

            if (_subscriber.SnapshotAndSubscribe(newEntry))
            {
                _needsUnsubscribe = true;
            }

            return newEntry;
        }
Ejemplo n.º 13
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 virtual bool ShouldInclude(ValueBuffer valueBuffer) => false;
Ejemplo n.º 14
0
 private bool Equals(ValueBuffer other)
 => Equals(_values, other._values) &&
 _offset == other._offset;
 /// <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 virtual InternalEntityEntry Create(IStateManager stateManager, IEntityType entityType, object entity, ValueBuffer valueBuffer)
     => NewInternalEntityEntry(stateManager, entityType, entity, valueBuffer);