英文:
How to run service on every table update
问题
我想在特定的 Azure SQL Server 表中添加/删除数据时实现在 Entity Framework Core 中运行特定服务的方法。一般来说,我想知道如果执行是在更新特定表时完成的,这是如何实现的。
我希望它与数据库触发器同时运行。在所有数据已应用到实际数据库后,我需要向 Service Bus 发送一条消息。
英文:
I want to implement a way to run a specific service in Entity Framework Core when data is added/deleted in a specific azure sql server's table. In general, I'm wondering how this is implemented if the execution is done on updates to a specific table.
I want it to work at the same time as the DB trigger is firing. I need to send a message to the servicebus after all the data has been applied to the actual database
答案1
得分: 0
使用这种方法,创建一个依赖于YourDbContext的自定义仓储类(YourEntityRepository)。在仓储类中,您定义了用于添加和删除实体的方法,在这些方法中,您可以相应地执行您的特定服务方法(YourSpecificService)。SaveChanges方法可用于将更改持久保存到数据库。
英文:
Use this approach, create a custom repository class (YourEntityRepository) that depends on your YourDbContext. Within the repository class, you define methods for adding and deleting entities, where you can execute your specific service methods (YourSpecificService) accordingly. The SaveChanges method can be used to persist the changes to the database.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论