如何在每次表格更新时运行服务。

huangapple go评论51阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月5日 08:40:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76402965.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定