Exemple #1
0
        public static IQueryable <TElement> ExpandInvocations <TElement>(this IQueryable <TElement> query)
        {
            Validation.CheckArgumentNotNull(query, "query");

            return(query.Provider.CreateQuery <TElement>(query.Expression.ExpandInvocations()));
        }
Exemple #2
0
        /// <summary>
        ///     Returns a handle on an IDisposable that can be used to safely control the lifetime
        ///     of an open connection. If the connection is closed, it will be opened immediately
        ///     and closed when the result of this method (the scope) is disposed. If the connection is already
        ///     open, it remains open.
        ///     <code>
        /// // Example with CreateConnectionScope
        /// using (command.Connection.CreateConnectionScope())
        /// {
        ///     command.ExecuteNonQuery();
        /// }
        ///
        /// // Example without
        /// bool connectionOpened = command.Connection.State == ConnectionState.Closed;
        /// if (connectionOpened)
        /// {
        ///     command.Connection.Open();
        /// }
        /// try
        /// {
        ///     command.ExecuteNonQuery();
        /// }
        /// finally
        /// {
        ///     if (connectionOpened &amp;&amp; command.Connection.State == ConnectionState.Open)
        ///     {
        ///         command.Connection.Close();
        ///     }
        /// }
        /// </code>
        /// </summary>
        /// <param name="connection">Connection to open.</param>
        /// <returns>Scope closing the connection on dispose.</returns>
        public static IDisposable CreateConnectionScope(this DbConnection connection)
        {
            Validation.CheckArgumentNotNull(connection, "connection");

            return(new OpenConnectionLifetime(connection));
        }