-
Notifications
You must be signed in to change notification settings - Fork 179
Include old values
Christian Del Bianco edited this page May 22, 2018
·
2 revisions
In order to get the old value too, simply set includeOldValues = true and retrieve the old value in OnChanged event handler as shown below:
string ConnectionString = "data source=.;initial catalog=myDB;integrated security=True";
string tableName = "Clients";
string schemaName = "dbo";
using(var tableDependency = new SqlTableDependency<Customers>(
ConnectionString,
schemaName: schemaName,
tableName: tableName,
includeOldValues: true))
{
tableDependency.OnChanged += TableDependency_Changed;
tableDependency.Start();
Console.WriteLine("Waiting for receiving notifications...");
Console.WriteLine("Press a key to stop");
Console.ReadKey();
}
}
....
private void TableDependency_Changed2(object sender, RecordChangedEventArgs<Customers>
{
switch (e.ChangeType)
{
case ChangeType.Insert:
CheckValues2[ChangeType.Insert.ToString()].Add(e.Entity);
break;
case ChangeType.Update:
CheckValues2[ChangeType.Update.ToString()].Add(e.Entity);
CheckValuesOld2[ChangeType.Update.ToString()].Add(e.EntityOldValues);
break;
case ChangeType.Delete:
CheckValues2[ChangeType.Delete.ToString()].Add(e.Entity);
break;
}
}