예제 #1
0
        /// <summary>
        ///     Stores an entity instance to the database.
        /// </summary>
        /// <param name="entity">
        ///     The entity to store.
        /// </param>
        /// <param name="ignoreKeys">
        ///     The keys to ignore.
        /// </param>
        /// <param name="behaviors">
        ///     The behaviors.
        /// </param>
        /// <typeparam name="T">
        ///     The entity type.
        /// </typeparam>
        public void Persist <T>(T entity, ISet <Key> ignoreKeys, Behaviors behaviors) where T : class
        {
            EntityWriter.Persist(this, entity, ignoreKeys, behaviors);

            if (behaviors.BypassWriteCache())
            {
                this.entitiesWritten.Remove(entity);
            }
        }
예제 #2
0
        /// <summary>
        ///     Stores an entity instance to the database.
        /// </summary>
        /// <param name="entity">
        ///     The entity to store.
        /// </param>
        /// <param name="behaviors">
        ///     The behaviors.
        /// </param>
        /// <typeparam name="T">
        ///     The entity type.
        /// </typeparam>
        public void Persist <T>(T entity, Behaviors behaviors) where T : class
        {
            if (behaviors.IsCreateNew() && !behaviors.DoNotCache() && !behaviors.BypassWriteCache())
            {
                var entityReference = this.EntityReferenceForType(entity.GetType());
                if (entityReference != null)
                {
                    bool newEntity;
                    var  key = entityReference.GetKeyFromEntity(entity, out newEntity);
                    if (!newEntity)
                    {
                        var entitySpec = new EntitySpec(entityReference, key);
                        this.entitySpecsWritten.Remove(entitySpec);
                    }
                }
            }

            EntityWriter.Persist(this, entity, behaviors);
        }
예제 #3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="EntityWriter" /> class.
        /// </summary>
        /// <param name="entityContext">
        ///     The entity context.
        /// </param>
        /// <param name="entityType">
        ///     The entity type.
        /// </param>
        /// <param name="entity">
        ///     The entity.
        /// </param>
        /// <param name="ignoreKeys">
        ///     The keys to ignore.
        /// </param>
        /// <param name="behaviors">
        ///     The behaviors.
        /// </param>
        /// <param name="entitiesWritten">
        ///     The entities written.
        /// </param>
        /// <exception cref="ArgumentException">
        ///     If <see cref="Behaviors.DoNotCache" /> has been combined with <see cref="Behaviors.CreateLazy" />.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     If <see cref="Behaviors.BypassWriteCache" /> has been combined with <see cref="Behaviors.CreateLazy" />.
        /// </exception>
        private EntityWriter(EntityContext entityContext, ISet <Key> ignoreKeys, Behaviors behaviors,
                             ISet <object> entitiesWritten)
        {
            if (behaviors.IsCreateLazy())
            {
                if (behaviors.DoNotCache())
                {
                    throw new ArgumentException(@"DontCache cannot be combined with CreateLazy", nameof(behaviors));
                }

                if (behaviors.BypassWriteCache())
                {
                    throw new ArgumentException(@"BypassWriteCache cannot be combined with CreateLazy", nameof(behaviors));
                }
            }

            this.entityContext   = entityContext;
            this.ignoreKeys      = ignoreKeys;
            this.behaviors       = behaviors;
            this.entitiesWritten = entitiesWritten;
            this.reviewKey       = entityContext.Configuration.ReviewKey;
        }
예제 #4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="EntityWriter" /> class.
        /// </summary>
        /// <param name="entityContext">
        ///     The entity context.
        /// </param>
        /// <param name="entityType">
        ///     The entity type.
        /// </param>
        /// <param name="entity">
        ///     The entity.
        /// </param>
        /// <param name="behaviors">
        ///     The behaviors.
        /// </param>
        /// <param name="entitiesWritten">
        ///     The entities written.
        /// </param>
        /// <exception cref="ArgumentException">
        ///     If <see cref="Behaviors.DoNotCache" /> has been combined with <see cref="Behaviors.CreateLazy" />.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     If <see cref="Behaviors.BypassWriteCache" /> has been combined with <see cref="Behaviors.CreateLazy" />.
        /// </exception>
        private EntityWriter(EntityContext entityContext, Type entityType, object entity, Behaviors behaviors,
                             IdentitySet entitiesWritten)
        {
            if (behaviors.IsCreateLazy())
            {
                if (behaviors.DoNotCache())
                {
                    throw new ArgumentException(@"DontCache cannot be combined with CreateLazy", nameof(behaviors));
                }

                if (behaviors.BypassWriteCache())
                {
                    throw new ArgumentException(@"BypassWriteCache cannot be combined with CreateLazy", nameof(behaviors));
                }
            }

            this.entityContext      = entityContext;
            this.behaviors          = behaviors;
            this.entityType         = entityType;
            this.entity             = entity;
            this.entitiesWritten    = entitiesWritten;
            this.entitySpecsWritten = entityContext.EntitySpecsWritten;
            this.entitySpecsFetched = entityContext.EntitySpecsFetched;
        }