예제 #1
0
        /// <summary>
        ///     Call this method from the constructor of a class derived from <see cref="DbConfiguration" /> to set
        ///     an implementation of <see cref="IDbModelCacheKeyFactory" /> which allows the key used to cache the
        ///     model behind a <see cref="DbContext" /> to be changed.
        /// </summary>
        /// <remarks>
        ///     This method is provided as a convenient and discoverable way to add configuration to the entity framework.
        ///     Internally it works in the same way as using AddDependencyResolver to add an appropriate resolver for
        ///     <see cref="IDbModelCacheKeyFactory" />. This means that, if desired, the same functionality can be achieved using
        ///     a custom resolver or a resolved backed by an Inversion-of-Control container.
        /// </remarks>
        /// <param name="keyFactory"> The key factory. </param>
        protected internal void SetModelCacheKeyFactory(IDbModelCacheKeyFactory keyFactory)
        {
            Check.NotNull(keyFactory, "keyFactory");

            _internalConfiguration.CheckNotLocked("SetModelCacheKeyFactory");
            _internalConfiguration.RegisterSingleton(keyFactory, null);
        }
예제 #2
0
        /// <summary>
        ///     Constructs a <see cref="LazyInternalContext" /> for the given <see cref="DbContext" /> owner that will be initialized
        ///     on first use.
        /// </summary>
        /// <param name="owner">
        ///     The owner <see cref="DbContext" /> .
        /// </param>
        /// <param name="internalConnection"> Responsible for creating a connection lazily when the context is used for the first time. </param>
        /// <param name="model"> The model, or null if it will be created by convention </param>
        public LazyInternalContext(
            DbContext owner,
            IInternalConnection internalConnection,
            DbCompiledModel model,
            IDbModelCacheKeyFactory cacheKeyFactory = null)
            : base(owner)
        {
            DebugCheck.NotNull(internalConnection);

            _internalConnection = internalConnection;
            _model           = model;
            _cacheKeyFactory = cacheKeyFactory ?? new DefaultModelCacheKeyFactory();

            _createdWithExistingModel = model != null;
        }
        /// <summary>
        ///     Constructs a <see cref = "LazyInternalContext" /> for the given <see cref = "DbContext" /> owner that will be initialized
        ///     on first use.
        /// </summary>
        /// <param name = "owner">The owner <see cref = "DbContext" />.</param>
        /// <param name = "internalConnection">Responsible for creating a connection lazily when the context is used for the first time.</param>
        /// <param name = "model">The model, or null if it will be created by convention</param>
        public LazyInternalContext(
            DbContext owner,
            IInternalConnection internalConnection,
            DbCompiledModel model,
            IDbModelCacheKeyFactory cacheKeyFactory = null)
            : base(owner)
        {
            //Contract.Requires(internalConnection != null);

            _internalConnection = internalConnection;
            _model = model;
            _cacheKeyFactory = cacheKeyFactory ?? new DefaultModelCacheKeyFactory();

            _createdWithExistingModel = model != null;
        }
        /// <summary>
        ///     Constructs a <see cref="LazyInternalContext" /> for the given <see cref="DbContext" /> owner that will be initialized
        ///     on first use.
        /// </summary>
        /// <param name="owner">
        ///     The owner <see cref="DbContext" /> .
        /// </param>
        /// <param name="internalConnection"> Responsible for creating a connection lazily when the context is used for the first time. </param>
        /// <param name="model"> The model, or null if it will be created by convention </param>
        public LazyInternalContext(
            DbContext owner,
            IInternalConnection internalConnection,
            DbCompiledModel model,
            IDbModelCacheKeyFactory cacheKeyFactory = null,
            AttributeProvider attributeProvider = null)
            : base(owner)
        {
            DebugCheck.NotNull(internalConnection);

            _internalConnection = internalConnection;
            _model = model;
            _cacheKeyFactory = cacheKeyFactory ?? new DefaultModelCacheKeyFactory();
            _attributeProvider = attributeProvider ?? new AttributeProvider();

            _createdWithExistingModel = model != null;
        }