处理数据库中的历史/更改跟踪以及对 BL 的影响
在当前的应用程序中,我正在为客户工作,要求我们保存系统中发生的每个操作的历史记录,并提供回溯到信息之前状态的能力。
例如:假设我的应用程序需要处理一个储藏室,并且
如果用户使用操作 A1 添加产品 P1 并更新其信息,使其变为 P2, 则每个用户都可以添加/更新/删除/读取(所有 CRUD)库存操作 A2 以及稍后的 P3、P4 等。 在应用程序中,用户将拥有一个显示产品所有演变的屏幕和一个显示用户所做的所有操作的屏幕。 用户可以选择某个操作并“撤消”它。
乍一看,我认为我将存储某种操作表,其中包含我需要的有关该操作的所有信息,当我需要撤消和操作时,我只需恢复代码中的更改即可。
我的问题是:如果产品没有存储在一个表中而是分为几个表(由于优化/可理解性等),我需要弄清楚更改到底在哪里。
我应该在操作表中保留哪些表受到影响并将其反映给 BL???
在我看来必须有更好的解决方案
in the current application im working on the client requested that we will save history of every action that happended in the system and provide the ability to backtrack to the previous state of the information.
for example: lets say that my app need to handle a storage-room and each user can add/update/delete/read (all CRUD) the inventory
if the user added product P1 with action A1 and updated its info so it becomes P2 with action A2 and later on P3, P4 and so on. in the application the user will have a screen that will show all the evolution of the product and ascreen that shows all the actions that were made by users.
the user could select a certain action and "undo" it.
at first glance i thought that i will store some kind of a Actions table with all the info i need about the action and when i need to undo and action i just revert the changes in code.
my problem is: if the product is not stored in one table but divided to few tables (because of optimization/understandability etc.) i need to figure out where exactly were the changes.
should i keep an indication in the Actions table of what tables were influenced and reflect it to the BL????
seems to me that there must be a better solution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我曾经做过类似的事情,为了能够恢复更改,您需要跟踪更改的字段。
只要您知道该字段的位置,该字段的位置并不重要。
因此,您可以在 BL 中创建一种辅助类,它“知道”每个字段的放置位置并将其映射到数据库中正确的表 -> 列。 这将减少 BL 中的字符串和其他 DB 元素。
只需将这个辅助类放入 DAL 中即可。
当您需要查看更改(和/或恢复它们)时,请向 DAL 发送问题...
顺便说一下,MS-SQL 2008 中有内置的更改跟踪,因此您可以使用它来查找更改。 - 更改跟踪
I did somthing like that once and to be able to revert changes you need to keep track on the field that change.
It doesn't matter where this fiels place as long as you know where this field placed.
So you can make in your BL a kind of helper class that "know" where every field placed and map it to the right table->column in DB. this will reduce the strings and other DB elements in your BL.
Just put this helper class in DAL.
When you need to see changes (and/or revert them) send question to DAL...
By the way in MS-SQL 2008 there is built-in change tracking so you can use it to look for changes. - Change Tracking
也许使用更具体的操作,以便应用程序确切地知道要做什么,而
不是将逻辑放在数据库上
perhaps using a more particular action so that the application will know exactly what todo
dont put logic on the DB