开发者

Entity Framework push-based change tracking

开发者 https://www.devze.com 2023-03-10 16:04 出处:网络
Does Entity Framework innately support any sort of change tracking in terms of detecting which records in a database were added af开发者_如何学Pythonter some date x and which were added before some da

Does Entity Framework innately support any sort of change tracking in terms of detecting which records in a database were added af开发者_如何学Pythonter some date x and which were added before some date x? I know it supports tracking changes in the properties of entities themselves, but this is a bit different, I think.

If not in Entity Framework, I'm wondering what would be recommended for a simple way to achieve this.

The scenario would be that automatic push-based data transfers are occurring say, every hour, and each time a push is initiated the server has to know which records have been added since the last push, and push those.

Does anyone know a standard and reliable approach to this? I've created my own solutions (watching primary keys, DateTime columns, etc.) but would rather not reinvent the wheel.


The feature you're looking for are exactly Change Tracking (tracks the rows changed for sync like scenarios) and/or Change Data Capture (tracks exactly what changes, including pre-change image of data, for more complex scenarios like audit). There is a comparison of the two at Comparing Change Data Capture and Change Tracking, which covers also the main scenarios each of these two addresses. Note that 'roll your own' does not work because you need special support in the engine to either detect certain kind of changes, or prevent operations that would result in breaking the change tracking.

Entity Framework has nothing to do with these operations.


I don't think Entity Framework provides what you are looking for. I could think of two solutions out of the top of my head (Assuming you're using MS SQL Server):

Use a rowversion column and have your update check routing update another column with the current rowversion. If, when the change checking routing runs again, the rowversion does not match the rowversioncopy you know it has been modified. This may or may not be a feasible approach depending on how many rows you're dealing with.

Another approach would be to use triggers on tables and have them fire your change handling.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号