我正在尝试在我的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的预期行为还是我的用法出错?
答案 0 :(得分:1)
似乎只能观察整个表格(http://social.msdn.microsoft.com/Forums/en-US/sqlservicebroker/thread/acb94617-bafc-4e28-bc63-ddfd23ab2379) - 这是正确的吗?