Normally I would plug into either the service creating the Transaction or the Save changes event like @Vince Suggested However because of your new requirement
the problem is: I don't have this control over the sdk that pushes the transactions of students to db, so I hope that there's some way to work directly over the db table.
In you're case you can just watch the table using SQL Dependencies
Note: Be careful using SqlDependency class - it has problems with memory leaks.
using(var tableDependency = new SqlTableDependency<Transaction>(conString))
{
tableDependency.OnChanged += TableDependency_Changed;
tableDependency.Start();
}
void TableDependency_Changed(object sender, RecordChangedEventArgs<Transaction> e)
{
if (e.ChangeType != ChangeType.None)
{
var changedEntity = e.Entity;
//You'll need to change this logic to send only to the people you want to
IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
hubContext.Clients.All.notifyClients(entity);
}
}
Edit
It seems you may have other dependencies e.g include you want with your results.
So what you can do is resolve the Id from the entity and then call Get using EntityFramework.
if (e.ChangeType != ChangeType.None)
{
var changedEntity = e.Entity;
var id = GetPrimaryKey(changedEntity)
_ctx.Transactions.Find(id);
}
Edit
Other Methods of approach.
If you're entities have a last updated field you can scan for changes to the table on a timer. Client has a timer when it elapses it send the in the last time it checked for changes. The server the obtains all of entities who have an last update time stamp greater than the time passed in
Although you don't have access to the EF, you probably have access to the web api requests. Whenever someone calls an update or create method, just grab the id of the changed entity, pop all the ids of the entities changed onto a background service which will send the signalr notifications,
The only issue now is obtaining the primary key that can be done with a manual mapping of the types to their id property, or it can be done using the metadata from the model but that's a bit more complicated
Note you probably can modify this so it works generically on all tables