Esempio n. 1
0
 public virtual void NotifyReaderCreated([NotNull] DbDataReader dataReader)
 => NonCapturingLazyInitializer
 .EnsureInitialized(
     ref _valueBufferFactory,
     new FactoryAndReader(_valueBufferFactoryFactory, dataReader),
     s => QuerySqlGeneratorFactory()
     .CreateValueBufferFactory(s.Factory, s.Reader));
        /// <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 TContext Rent()
        {
            TContext context;

            if (_pool.TryDequeue(out context))
            {
                Interlocked.Decrement(ref _count);

                Debug.Assert(_count >= 0);

                ((IDbContextPoolable)context).Resurrect(_configurationSnapshot);

                return(context);
            }

            context = _activator();

            NonCapturingLazyInitializer
            .EnsureInitialized(
                ref _configurationSnapshot,
                (IDbContextPoolable)context,
                c => c.SnapshotConfiguration());

            ((IDbContextPoolable)context).SetPool(this);

            return(context);
        }
Esempio n. 3
0
        private void SetUdtTypeName(DbParameter parameter)
        {
            NonCapturingLazyInitializer.EnsureInitialized(
                ref _udtTypeNameSetter,
                parameter.GetType(),
                CreateUdtTypeNameAccessor);

            _udtTypeNameSetter(parameter, UdtTypeName);
        }
Esempio n. 4
0
        private void SetUdtTypeName(DbParameter parameter)
        {
            NonCapturingLazyInitializer.EnsureInitialized(
                ref _udtTypeNameSetter,
                parameter.GetType(),
                CreateUdtTypeNameAccessor);

            if (parameter.Value != null && parameter.Value != DBNull.Value)
            {
                _udtTypeNameSetter(parameter, UdtTypeName);
            }
        }
        private Func <QueryContext, TResult> EnsureExecutor(TContext context)
        => NonCapturingLazyInitializer.EnsureInitialized(
            ref _executor,
            context,
            _queryExpression,
            (c, q) =>
        {
            var queryCompiler = context.GetService <IQueryCompiler>();
            var expression    = new QueryExpressionRewriter(c, q.Parameters).Visit(q.Body);

            return(CreateCompiledQuery(queryCompiler, expression));
        });
Esempio n. 6
0
 public static ITestStoreFactory EnsureInitialized(
     ref ITestStoreFactory inst,
     InfoCarrierBackendTestStoreFactory backendTestStoreFactory,
     Type contextType,
     Action <ModelBuilder, DbContext> onModelCreating,
     Func <DbContextOptionsBuilder, DbContextOptionsBuilder> onAddOptions = null,
     Action <DbContext, DbContext> copyDbContextParameters = null)
 => NonCapturingLazyInitializer.EnsureInitialized(
     ref inst,
     inst,
     _ => new InfoCarrierTestStoreFactory(
         new SharedTestStoreProperties
 {
     ContextType             = contextType,
     OnModelCreating         = onModelCreating,
     OnAddOptions            = onAddOptions ?? (o => o),
     CopyDbContextParameters = copyDbContextParameters,
 },
         backendTestStoreFactory));
Esempio n. 7
0
 /// <summary>
 ///     <para>
 ///         Creates a snapshot of the given instance.
 ///     </para>
 ///     <para>
 ///         Snapshotting is the process of creating a copy of the value into a snapshot so it can
 ///         later be compared to determine if it has changed. For some types, such as collections,
 ///         this needs to be a deep copy of the collection rather than just a shallow copy of the
 ///         reference.
 ///     </para>
 /// </summary>
 /// <param name="instance"> The instance. </param>
 /// <returns> The snapshot. </returns>
 public virtual T Snapshot([CanBeNull] T instance)
 => NonCapturingLazyInitializer.EnsureInitialized(
     ref _snapshot, this, c => c.SnapshotExpression.Compile())(instance);
Esempio n. 8
0
 /// <summary>
 ///     Returns the hash code for the given instance.
 /// </summary>
 /// <param name="instance"> The instance. </param>
 /// <returns> The hash code. </returns>
 public virtual int GetHashCode(T instance)
 => NonCapturingLazyInitializer.EnsureInitialized(
     ref _hashCode, this, c => c.HashCodeExpression.Compile())(instance);
Esempio n. 9
0
 /// <summary>
 ///     Compares the two instances to determine if they are equal.
 /// </summary>
 /// <param name="left"> The first instance. </param>
 /// <param name="right"> The second instance. </param>
 /// <returns> <c>True</c> if they are equal; <c>false</c> otherwise. </returns>
 public virtual bool Equals(T left, T right)
 => NonCapturingLazyInitializer.EnsureInitialized(
     ref _equals, this, c => c.EqualsExpression.Compile())(left, right);
Esempio n. 10
0
 /// <summary>
 ///     <para>
 ///         Creates a snapshot of the given instance.
 ///     </para>
 ///     <para>
 ///         Snapshotting is the process of creating a copy of the value into a snapshot so it can
 ///         later be compared to determine if it has changed. For some types, such as collections,
 ///         this needs to be a deep copy of the collection rather than just a shallow copy of the
 ///         reference.
 ///     </para>
 /// </summary>
 /// <param name="instance"> The instance. </param>
 /// <returns> The snapshot. </returns>
 public override object Snapshot(object instance)
 => NonCapturingLazyInitializer.EnsureInitialized(
     ref _snapshot,
     this,
     c => c.SnapshotExpression.Compile())
 .DynamicInvoke(instance);
Esempio n. 11
0
 /// <summary>
 ///     Returns the hash code for the given instance.
 /// </summary>
 /// <param name="instance"> The instance. </param>
 /// <returns> The hash code. </returns>
 public override int GetHashCode(object instance)
 => (int)NonCapturingLazyInitializer.EnsureInitialized(
     ref _hashCode,
     this,
     c => c.HashCodeExpression.Compile())
 .DynamicInvoke(instance);
Esempio n. 12
0
 /// <summary>
 ///     Compares the two instances to determine if they are equal.
 /// </summary>
 /// <param name="left"> The first instance. </param>
 /// <param name="right"> The second instance. </param>
 /// <returns> <c>True</c> if they are equal; <c>false</c> otherwise. </returns>
 public override bool Equals(object left, object right)
 => (bool)NonCapturingLazyInitializer.EnsureInitialized(
     ref _equals,
     this,
     c => c.EqualsExpression.Compile())
 .DynamicInvoke(left, right);
Esempio 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 IPrincipalKeyValueFactory <TKey> GetPrincipalKeyValueFactory <TKey>()
 => (IPrincipalKeyValueFactory <TKey>)NonCapturingLazyInitializer.EnsureInitialized(
     ref _principalKeyValueFactory, this, k => new KeyValueFactoryFactory().Create <TKey>(k));
Esempio n. 14
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 INullableValueFactory <TKey> GetNullableValueFactory <TKey>()
 => (INullableValueFactory <TKey>)NonCapturingLazyInitializer.EnsureInitialized(
     ref _nullableValueFactory, this, i => new CompositeNullableValueFactory(i.Properties));