Example #1
0
        private EntityEntry SetEntityState(object entity, EntityState entityState, GraphBehavior behavior)
        {
            var entry = EntryWithoutDetectChanges(entity);

            SetEntityState(entry.GetInfrastructure(), entityState, behavior);

            return(entry);
        }
Example #2
0
        private static GraphBehavior IsDefined(GraphBehavior behavior)
        {
            if (behavior != GraphBehavior.IncludeDependents &&
                behavior != GraphBehavior.SingleObject)
            {
                throw new ArgumentException(CoreStrings.InvalidEnumValue(nameof(behavior), typeof(GraphBehavior)));
            }

            return(behavior);
        }
Example #3
0
        private EntityEntry <TEntity> SetEntityState <TEntity>(
            TEntity entity,
            EntityState entityState,
            GraphBehavior behavior) where TEntity : class
        {
            var entry = EntryWithoutDetectChanges(entity);

            SetEntityState(entry.GetInfrastructure(), entityState, behavior);

            return(entry);
        }
Example #4
0
 public override void UpdateRange(IEnumerable <TEntity> entities, GraphBehavior behavior = GraphBehavior.IncludeDependents)
 => _context.UpdateRange(Check.NotNull(entities, nameof(entities)), behavior);
Example #5
0
 public override EntityEntry <TEntity> Update(TEntity entity, GraphBehavior behavior = GraphBehavior.IncludeDependents)
 => _context.Update(Check.NotNull(entity, nameof(entity)), behavior);
Example #6
0
 /// <summary>
 ///     <para>
 ///         Begins tracking the given entities in the <see cref="EntityState.Modified" /> state such that they will
 ///         be updated in the database when <see cref="SaveChanges()" /> is called.
 ///     </para>
 ///     <para>
 ///         All properties of the entities will be marked as modified. To mark only some properties as modified, use
 ///         <see cref="Attach(object, GraphBehavior)" /> to begin tracking each entity in the <see cref="EntityState.Unchanged" />
 ///         state and then use the returned <see cref="EntityEntry" /> to mark the desired properties as modified.
 ///     </para>
 /// </summary>
 /// <param name="entities"> The entities to update. </param>
 /// <param name="behavior">
 ///     Determines whether the context will bring in only the given entities or also other related entities.
 /// </param>
 public virtual void UpdateRange(
     [NotNull] IEnumerable <object> entities,
     GraphBehavior behavior = GraphBehavior.IncludeDependents)
 => SetEntityStates(Check.NotNull(entities, nameof(entities)), EntityState.Modified, Check.IsDefined(behavior, nameof(behavior)));
Example #7
0
        private void SetEntityStates(IEnumerable <object> entities, EntityState entityState, GraphBehavior behavior)
        {
            var stateManager = GetStateManager();

            foreach (var entity in entities)
            {
                SetEntityState(stateManager.GetOrCreateEntry(entity), entityState, behavior);
            }
        }
Example #8
0
 /// <summary>
 ///     <para>
 ///         Begins tracking the given entity in the <see cref="EntityState.Modified" /> state such that it will
 ///         be updated in the database when <see cref="SaveChanges()" /> is called.
 ///     </para>
 ///     <para>
 ///         All properties of the entity will be marked as modified. To mark only some properties as modified, use
 ///         <see cref="Attach(object, GraphBehavior)" /> to begin tracking the entity in the <see cref="EntityState.Unchanged" />
 ///         state and then use the returned <see cref="EntityEntry" /> to mark the desired properties as modified.
 ///     </para>
 /// </summary>
 /// <param name="entity"> The entity to update. </param>
 /// <param name="behavior">
 ///     Determines whether the context will bring in only the given entity or also other related entities.
 /// </param>
 /// <returns>
 ///     The <see cref="EntityEntry" /> for the entity. The entry provides
 ///     access to change tracking information and operations for the entity.
 /// </returns>
 public virtual EntityEntry Update(
     [NotNull] object entity,
     GraphBehavior behavior = GraphBehavior.IncludeDependents)
 => SetEntityState(Check.NotNull(entity, nameof(entity)), EntityState.Modified, Check.IsDefined(behavior, nameof(behavior)));
Example #9
0
 /// <summary>
 ///     <para>
 ///         Begins tracking the given entity in the <see cref="EntityState.Modified" /> state such that it will
 ///         be updated in the database when <see cref="SaveChanges()" /> is called.
 ///     </para>
 ///     <para>
 ///         All properties of the entity will be marked as modified. To mark only some properties as modified, use
 ///         <see cref="Attach{TEntity}(TEntity, GraphBehavior)" /> to begin tracking the entity in the
 ///         <see cref="EntityState.Unchanged" /> state and then use the returned <see cref="EntityEntry{TEntity}" />
 ///         to mark the desired properties as modified.
 ///     </para>
 /// </summary>
 /// <typeparam name="TEntity"> The type of the entity. </typeparam>
 /// <param name="entity"> The entity to update. </param>
 /// <param name="behavior">
 ///     Determines whether the context will bring in only the given entity or also other related entities.
 /// </param>
 /// <returns>
 ///     The <see cref="EntityEntry{TEntity}" /> for the entity. The entry provides
 ///     access to change tracking information and operations for the entity.
 /// </returns>
 public virtual EntityEntry <TEntity> Update <TEntity>(
     [NotNull] TEntity entity,
     GraphBehavior behavior = GraphBehavior.IncludeDependents) where TEntity : class
 => SetEntityState(Check.NotNull(entity, nameof(entity)), EntityState.Modified, Check.IsDefined(behavior, nameof(behavior)));
Example #10
0
 private void SetEntityState(InternalEntityEntry entry, EntityState entityState, GraphBehavior behavior)
 {
     if (behavior == GraphBehavior.IncludeDependents &&
         entry.EntityState == EntityState.Detached)
     {
         ServiceProvider.GetRequiredService <IEntityGraphAttacher>().AttachGraph(entry, entityState);
     }
     else
     {
         entry.SetEntityState(entityState, acceptChanges: true);
     }
 }
Example #11
0
 /// <summary>
 ///     Begins tracking the given entity in the <see cref="EntityState.Unchanged" /> state such that no
 ///     operation will be performed when <see cref="DbContext.SaveChanges()" /> is called.
 /// </summary>
 /// <param name="entity"> The entity to attach. </param>
 /// <param name="behavior">
 ///     Determines whether the context will bring in only the given entity or also other related entities.
 /// </param>
 /// <returns>
 ///     The <see cref="EntityEntry" /> for the entity. The entry provides
 ///     access to change tracking information and operations for the entity.
 /// </returns>
 public virtual EntityEntry <TEntity> Attach(
     [NotNull] TEntity entity,
     GraphBehavior behavior = GraphBehavior.IncludeDependents)
 {
     throw new NotImplementedException();
 }
Example #12
0
 /// <summary>
 ///     <para>
 ///         Begins tracking the given entities in the <see cref="EntityState.Modified" /> state such that they will
 ///         be updated in the database when <see cref="DbContext.SaveChanges()" /> is called.
 ///     </para>
 ///     <para>
 ///         All properties of the entities will be marked as modified. To mark only some properties as modified, use
 ///         <see cref="Attach(TEntity, GraphBehavior)" /> to begin tracking each entity in the <see cref="EntityState.Unchanged" />
 ///         state and then use the returned <see cref="EntityEntry" /> to mark the desired properties as modified.
 ///     </para>
 /// </summary>
 /// <param name="entities"> The entities to update. </param>
 /// <param name="behavior">
 ///     Determines whether the context will bring in only the given entities or also other related entities.
 /// </param>
 public virtual void UpdateRange(
     [NotNull] IEnumerable <TEntity> entities,
     GraphBehavior behavior = GraphBehavior.IncludeDependents)
 {
     throw new NotImplementedException();
 }
Example #13
0
 /// <summary>
 ///     Begins tracking the given entities in the <see cref="EntityState.Unchanged" /> state such that no
 ///     operation will be performed when <see cref="SaveChanges()" /> is called.
 /// </summary>
 /// <param name="entities"> The entities to attach. </param>
 /// <param name="behavior">
 ///     Determines whether the context will bring in only the given entities or also other related entities.
 /// </param>
 public virtual void AttachRange(
     [NotNull] IEnumerable <object> entities,
     GraphBehavior behavior = GraphBehavior.IncludeDependents)
 => SetEntityStates(Check.NotNull(entities, nameof(entities)), EntityState.Unchanged, IsDefined(behavior));
Example #14
0
 /// <summary>
 ///     Begins tracking the given entity in the <see cref="EntityState.Unchanged" /> state such that no
 ///     operation will be performed when <see cref="SaveChanges()" /> is called.
 /// </summary>
 /// <param name="entity"> The entity to attach. </param>
 /// <param name="behavior">
 ///     Determines whether the context will bring in only the given entity or also other related entities.
 /// </param>
 /// <returns>
 ///     The <see cref="EntityEntry" /> for the entity. The entry provides
 ///     access to change tracking information and operations for the entity.
 /// </returns>
 public virtual EntityEntry Attach(
     [NotNull] object entity,
     GraphBehavior behavior = GraphBehavior.IncludeDependents)
 => SetEntityState(Check.NotNull(entity, nameof(entity)), EntityState.Unchanged, IsDefined(behavior));
Example #15
0
 /// <summary>
 ///     Begins tracking the given entity in the <see cref="EntityState.Unchanged" /> state such that no
 ///     operation will be performed when <see cref="SaveChanges()" /> is called.
 /// </summary>
 /// <typeparam name="TEntity"> The type of the entity. </typeparam>
 /// <param name="entity"> The entity to attach. </param>
 /// <param name="behavior">
 ///     Determines whether the context will bring in only the given entity or also other related entities.
 /// </param>
 /// <returns>
 ///     The <see cref="EntityEntry{TEntity}" /> for the entity. The entry provides
 ///     access to change tracking information and operations for the entity.
 /// </returns>
 public virtual EntityEntry <TEntity> Attach <TEntity>(
     [NotNull] TEntity entity,
     GraphBehavior behavior = GraphBehavior.IncludeDependents) where TEntity : class
 => SetEntityState(Check.NotNull(entity, nameof(entity)), EntityState.Unchanged, IsDefined(behavior));