SqlDependency 没有选择性地工作?
我试图观察 SQL Server Express 2005 中的一些数据,如下所示:
SqlDependency.Stop(connectionString);
SqlDependency.Start(connectionString);
using (var con = new SqlConnection(connectionString))
{
con.Open();
var queryString = "SELECT [Name] FROM [dbo].[Persons]";
var command = new SqlCommand(queryString, con);
var dependency = new SqlDependency(command);
dependency.OnChange += OnQueryChanged;
command.ExecuteReader();
}
问题是我只对“名称”列更改时的回调感兴趣。但是,如果表“Persons”的另一列发生更改,也会调用 OnQueryChanged,如下所示:
var context = new Entities();
context.Persons.First().Street = "Foo";
context.SaveChanges();
这是 SqlDependency 的预期行为还是我在使用它时犯了错误?
I'm trying to observe some data in my SQL server express 2005 like this:
SqlDependency.Stop(connectionString);
SqlDependency.Start(connectionString);
using (var con = new SqlConnection(connectionString))
{
con.Open();
var queryString = "SELECT [Name] FROM [dbo].[Persons]";
var command = new SqlCommand(queryString, con);
var dependency = new SqlDependency(command);
dependency.OnChange += OnQueryChanged;
command.ExecuteReader();
}
The problem is that I'm only interested in a callback if the column "Name" changes. But OnQueryChanged is also called if another column of the table "Persons" is changed, like this:
var context = new Entities();
context.Persons.First().Street = "Foo";
context.SaveChanges();
Is this the intended behavior of SqlDependency or do I make a mistake in its usage?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎只能观察整个表(http://social.msdn.microsoft.com/Forums/en-US/sqlservicebroker/thread/acb94617-bafc-4e28-bc63-ddfd23ab2379) - 这是正确的吗?
It seems that it is only possible to observe whole tables (http://social.msdn.microsoft.com/Forums/en-US/sqlservicebroker/thread/acb94617-bafc-4e28-bc63-ddfd23ab2379) - is this correct?