I have a Web API where i want to trigger a function when a new row has been inserted to a DB table. I don't want to have to get all the data and look for new data manually.
Is it possible to have a SQL Server trigger that somehow calls a function in my C# Web API?
How can this be done? Is it a good idea?
You can override SubmitChanges in your DataContext, something like:
public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
{
var set = this.GetChangeSet();//list of pending changes
//Call your methods here
foreach (var insert in set.Inserts)
{
//Insert Logic
}
foreach (var update in set.Updates)
{
//Update Logic
}
foreach (var item in set.Deletes)
{
//Delete Logic
}
base.SubmitChanges(failureMode);//allow the DataContext to perform it's default work (including your new log changes)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With