/// <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 SqlNotificationListener(DbContext context, IQueryable query) { try { this._iquery = query; _context = context; // Get the ObjectQuery directly or convert the DbQuery to ObjectQuery. _oquery = QueryExtension.GetObjectQuery <TEntity>(context, _iquery); _connection = QueryExtension.GetSqlConnection(_oquery); _command = QueryExtension.GetSqlCommand(_oquery, _connection); } catch (ArgumentException ex) { if (ex.ParamName == "context") { throw new ArgumentException("Paramter cannot be null", nameof(context), ex); } throw new ArgumentException("Paramter cannot be null", nameof(query), ex); } catch (Exception ex) { throw new Exception( "Fails to initialize a new instance of SqlNotificationListener class.", ex); } }
/// <summary> /// Initializes a new instance of ImmediateNotificationRegister class. /// </summary> /// <param name="query">an instance of ObjectQuery is used to get _connection string and /// _command string to register SqlDependency nitification. </param> public SqlNotificationListener(ObjectQuery query) { try { this._oquery = query; _connection = QueryExtension.GetSqlConnection(_oquery); _command = QueryExtension.GetSqlCommand(query, _connection); } catch (ArgumentException ex) { throw new ArgumentException("Paramter cannot be null", nameof(query), ex); } catch (Exception ex) { throw new Exception( "Fails to initialize a new instance of SqlNotificationListener class.", ex); } }