This project is read-only.

OnChanged Event

Occurs when a notification is received for any change on the table's records associated with this SqlTableDependency object.

Syntax

public event ChangedEventHandler<T> OnChanged

Remarks

OnChange occurs when any table records change. In case of multiple records changed simultaneously, as result of a DELETE or UPDATE operation without WHERE condition, the event parameter will be composed of multiple items.

In case of SQL Server MERGE operation you will receive different C# events base on the DML (insert/update/delete) operation.

Let’s assume this SQL statement:

MERGE dbo.Customer AS TGT
USING dbo.CustomerStage AS SRC
ON TGT.Id = SRC.Id
WHEN MATCHED THEN
	UPDATE SET
	TGT.Name = SRC.Name,
	TGT.Surname = SRC.Surname
WHEN NOT MATCHED THEN
	INSERT (Id, Name, Surname)
	VALUES (SRC.Id, SRC.Name, SRC.Surname)
WHEN NOT MATCHED BY SOURCE THEN
	DELETE;

And let’s assume that the result of this SQL statement will be:
  • Two Update
  • One Delete
  • One Insert
SQL Server manages the MERGE operation base on the DML type and it performs the operations in the following order: first it executes the INSERT, than the UPDATE and finally the DELETE. This means that the trigger associated to the database table will fired three times generating three separated C# events.

Event sequence ChangeType ChangedEntities
First event Insert One (new) Customer entity
Second event Update Two (updated) Customer entities
Third event Delete One (deleted) Customer entity

Last edited Sep 10, 2015 at 11:02 AM by delbianco, version 2