/// <summary>
        /// Initializes a new instance of ImmediateNotificationRegister class.
        /// </summary>
        /// <param name="context">an instance of DbContext is used to get an ObjectQuery object</param>
        /// <param name="query">an instance of IQueryable is used to get ObjectQuery object, and then get
        /// connection string and command string to register SqlDependency nitification. </param>
        public ImmediateNotificationRegister(DbContext context, IQueryable query)
        {
            try
            {
                this.iquery = query;

                // Get the ObjectQuery directly or convert the DbQuery to ObjectQuery.
                oquery = QueryExtension.GetObjectQuery <TEntity>(context, iquery);

                QueryExtension.GetSqlCommand(oquery, ref connection, ref command);

                RegisterSqlDependency();
            }
            catch (ArgumentException ex)
            {
                if (ex.ParamName == "context")
                {
                    throw new ArgumentException("Paramter cannot be null", "context", ex);
                }
                else
                {
                    throw new ArgumentException("Paramter cannot be null", "query", ex);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(
                          "Fails to initialize a new instance of ImmediateNotificationRegister class.", ex);
            }
        }