LLBLGen:如何软删除条目
我继承了一个使用 LLBLGen Pro 作为 DB 层的项目。 DB 模型要求在删除条目时有一个标志(DeletedDate 设置为当前时间)。 最后一位程序员忽略了这一要求,并在整个应用程序中使用了常规删除。
有没有办法将代码生成器设置为自动执行此操作,或者我是否必须为需要它的实体重载每个删除运算符?
I have inherited a project that uses LLBLGen Pro for the DB layer. The DB model requires that when a entry is deleted a flag (DeletedDate is set to the current time). The last programmer ignored this requirement and has used regular deletes throughout the entire application.
Is there a way to set the code generator to do this automatically or do I have to overload each delete operator for the Entities that requires it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在 LLBLGen 中创建自定义任务,该任务将在您生成实体时覆盖这些任务。 在网站上查看他们的模板工作室和模板示例。
You could create custom task in LLBLGen that would override those for you when you are generating entities. Check out their template studio and template examples on the website.
这取决于您使用的是自助服务还是适配器。 如果 SS,您将需要修改模板,以便它为您设置标志而不是删除实体。
如果是适配器,您可以继承 DataAccessAdapter 并重写删除方法来设置标志,而不是删除实体。
这通常是一个蹩脚的性能解决方案,因为每个查询都需要过滤掉“已删除”实体 - 并且因为“已删除”列的选择性不会很高(所有“未删除”记录均为空 - i'我猜这将是其中的大多数)索引它不会给你带来很多好处 - 你最终会进行大量的表扫描。
It depends if you are using self-servicing or adapter. If SS you will need to modify the template so that it sets the flag for you rather than deleting the entity.
If adapter, you can inherit from DataAccessAdapter and override the delete methods to set the flag for you rather than deleting the entities.
It's generally a crappy solution for performace though as every query then needs to filter out "deleted" entities - and because the selectvity on the "deleted" column won't be very high (all of your "undelted" records are null - i'm guessing this will be the majority of them) indexing it doesn't gain you a great deal - you will end up with a lot of table scans.
我在 SQL Server 2005 中对任何软删除表的删除使用 INSTEAD OF 触发器来实现这一点。 触发器设置删除标志并执行清理。 该解决方案的优点在于它可以正确处理任何访问数据库的系统发出的删除操作。 INSTEAD OF 在 SQL Server 中相对较新,我知道 Oracle 中有一个等效的工具。
该解决方案还与我们的 O/R 映射器配合得很好——我创建了过滤掉软删除记录并映射这些记录的视图。 这些视图也用于所有报告。
I implemented this in SQL Server 2005 using INSTEAD OF triggers on delete for any soft delete table. The triggers set the delete flag and perform clean-up. The beauty of this solution is that it correctly handles deletes issued by any system that accesses the database. INSTEAD OF is relatively new in SQL Server, I know there's an Oracle equivalent.
This solution also plays nicely with our O/R mapper -- I created views that filter out soft deleted records and mapped those. The views are also used for all reporting.