简体   繁体   中英

How to minimize the calls in SqlTableDependency

If 100 rows are inserted in a table then only one call should be sent to get the values.

public static void InitiateSQLTableDependency()
    {
        try
        {
            var mapper = new ModelToTableMapper<DeviceValuesProperties>();
            mapper.AddMapping(deviceValue => deviceValue.DeviceId, "DeviceId");
            mapper.AddMapping(deviceValue => deviceValue.TimeStamp, "TimeStamp");

            tableDependency = new SqlTableDependency<DeviceValuesProperties>(connectionString, "DeviceValues", mapper);
            tableDependency.OnChanged += OnDependencyChange;
            tableDependency.OnError += OnDependencyError;
            tableDependency.Start();
            isSQLDependencyStart = true;
        }
        catch (Exception exception)
        {
            throw exception;
        }
        }

Sadly it doesn't work like that (assuming you are using this lib [ https://github.com/christiandelbianco/monitor-table-change-with-sqltabledependency] or even the standard SqlDependency. How often do you want this to fire? Every 100 rows? or every x time units? Why not just poll the table every so often? If you want it automatic but in bulk - You should look into either CDC, CDT or writing a trigger yourself;

https://docs.microsoft.com/en-us/sql/relational-databases/track-changes/about-change-data-capture-sql-server?view=sql-server-2017

https://docs.microsoft.com/en-us/sql/relational-databases/track-changes/work-with-change-tracking-sql-server?view=sql-server-2017

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM