开发者

Entity Framework for two applications and common database

I have two applications(web and a desktop app) that uses entity framework which use a common sql server database. They have unit of work pattern implemented and it keeps the context in the session or in the relevant thread. My question is how to update context of another application when one application updates something on th开发者_开发问答e database ? As an example let say the windows service has added some row to a table. How can the web application context get that one at the same time it is inserted.


Context in scenario of a web application should only last per the request. From what I see, you have to implement something as an event from database level as that seems to be the common place. This can be done using Triggers

In your scenario, you should perform following steps (just doing a drawing board scenario)

  • Add triggers at database level for each table, which will basically throw an event to the application layer.
  • Somehow extract those triggers into stored procedures, so that you can use with EF
  • Thereafter, implement a layer that sits on both the application whose primary responsibility is to notify the user of a change in the database by other application and then update the request by clicking a button(which in turn update the context). Basically the database level trigger, triggers something on the respective UI.

The meat of the work lies in the third point. You can achieve it in many ways. Alternatives are writing a service that polls another service (which accepts alerts from db trigger) for checking the modifications. so the logical separation could be like db --> service that accepts the change notification --> service that polls the notification service --> application

Above works logically and theoretically but hope it helps you out and I would be keen to know how you go about doing this.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜