Beispiel #1
0
 public virtual TResult Execute <TResult>(Func <TResult> operation)
 {
     if (!RetriesOnFailure)
     {
         return(operation());
     }
     return(_azureExecutionStrategy.Execute(operation));
 }
        public override bool AnyModelTableExistsInDatabase(
            ObjectContext context,
            DbConnection connection,
            IEnumerable <EntitySet> modelTables,
            string edmMetadataContextTableName)
        {
            StringBuilder stringBuilder = new StringBuilder();

            foreach (EntitySet modelTable in modelTables)
            {
                stringBuilder.Append("'");
                stringBuilder.Append((string)modelTable.MetadataProperties["Schema"].Value);
                stringBuilder.Append(".");
                stringBuilder.Append(this.GetTableName(modelTable));
                stringBuilder.Append("',");
            }
            stringBuilder.Remove(stringBuilder.Length - 1, 1);
            using (DbCommand command = connection.CreateCommand())
            {
                command.CommandText = "\r\nSELECT Count(*)\r\nFROM INFORMATION_SCHEMA.TABLES AS t\r\nWHERE t.TABLE_SCHEMA + '.' + t.TABLE_NAME IN (" + (object)stringBuilder + ")\r\n    OR t.TABLE_NAME = '" + edmMetadataContextTableName + "'";
                bool flag = true;
                if (DbInterception.Dispatch.Connection.GetState(connection, context.InterceptionContext) == ConnectionState.Open)
                {
                    flag = false;
                    EntityTransaction currentTransaction = ((EntityConnection)context.Connection).CurrentTransaction;
                    if (currentTransaction != null)
                    {
                        command.Transaction = currentTransaction.StoreTransaction;
                    }
                }
                IDbExecutionStrategy executionStrategy = DbProviderServices.GetExecutionStrategy(connection);
                try
                {
                    return(executionStrategy.Execute <bool>((Func <bool>)(() =>
                    {
                        if (DbInterception.Dispatch.Connection.GetState(connection, context.InterceptionContext) == ConnectionState.Broken)
                        {
                            DbInterception.Dispatch.Connection.Close(connection, context.InterceptionContext);
                        }
                        if (DbInterception.Dispatch.Connection.GetState(connection, context.InterceptionContext) == ConnectionState.Closed)
                        {
                            DbInterception.Dispatch.Connection.Open(connection, context.InterceptionContext);
                        }
                        return (int)DbInterception.Dispatch.Command.Scalar(command, new DbCommandInterceptionContext(context.InterceptionContext)) > 0;
                    })));
                }
                finally
                {
                    if (flag && DbInterception.Dispatch.Connection.GetState(connection, context.InterceptionContext) != ConnectionState.Closed)
                    {
                        DbInterception.Dispatch.Connection.Close(connection, context.InterceptionContext);
                    }
                }
            }
        }
        private ObjectResult <T> GetResults(MergeOption?forMergeOption)
        {
            this.QueryState.ObjectContext.AsyncMonitor.EnsureNotEntered();
            IDbExecutionStrategy executionStrategy = this.ExecutionStrategy ?? DbProviderServices.GetExecutionStrategy(this.QueryState.ObjectContext.Connection, this.QueryState.ObjectContext.MetadataWorkspace);

            if (executionStrategy.RetriesOnFailure && this.QueryState.EffectiveStreamingBehavior)
            {
                throw new InvalidOperationException(Strings.ExecutionStrategy_StreamingNotSupported((object)executionStrategy.GetType().Name));
            }
            return(executionStrategy.Execute <ObjectResult <T> >((Func <ObjectResult <T> >)(() => this.QueryState.ObjectContext.ExecuteInTransaction <ObjectResult <T> >((Func <ObjectResult <T> >)(() => this.QueryState.GetExecutionPlan(forMergeOption).Execute <T>(this.QueryState.ObjectContext, this.QueryState.Parameters)), executionStrategy, false, !this.QueryState.EffectiveStreamingBehavior))));
        }
        public DbConnection CreateConnection(string connectionStringName)
        {
            DbConnection connection = _retrySqlStrategy.Execute(() => CreateOpenConnection(connectionStringName));

            return(connection);
        }