Skip to content

Use case: Specify for which properties we want receive notification using UpdateOfModel T mapper

Christian Del Bianco edited this page May 22, 2018 · 3 revisions

Is possible define a list of property to monitor for changes. It means that we will receive notifications for table column changes that are mapped to that list.

Assuming a database table as:

CREATE TABLE [Person]( 
    [Id][int] IDENTITY(1, 1) NOT NULL, 
    [Name] [nvarchar](50) NOT NULL, 
    [Surname] [nvarchar](50) NOT NULL,
    [Born] [datetime] NULL)

Assuming a model as:

    public class Person
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Surname { get; set; }
    }

In order to receive notifications only when Name column is change, the following code can be used:

    var updateOfModel = new UpdateOfModel<Person>();
    updateOfModel.Add(i => i.Name);

    var tableDependency= new SqlTableDependency<Person>(
        ConnectionString, 
        updateOf: updateOfModel);

   tableDependency.OnChanged += TableDependency_Changed;
   tableDependency.Start();
   ...

A notification will be received only when a change on Person.Name table column happen.