efcore
efcore copied to clipboard
Cosmos: Support trigger execution
It is my understanding that CosmosDb has no way to turn triggers on by default. They have to be turned on per call. EF Core doesn't turn these on, so triggers can't be used with EF Core. While I understand the separate request for the change feed, I'm referring to built in triggers.
This prevents basic house keeping operations on nosql databases because of no joins. Typically you have data that is a subset of a referenced entity. This happens everywhere, but without triggers you can't update all of those references with the new subset of data of any of those fields change in the database. I.e. if I have a contact, and it's referenced somewhere else, I might include the Name and Email of that contact in some other container that has has a contact associated with it so that you can query and pull all of the information needed about that contact for display without having to separately query for the contacts and join it in memory.
If you have triggers, you can setup your contacts table to, by default, update all of the references in all other containers/objects when those fields change and update the reference information as necessary.
Without them, you have to do this logic in your C# logic every time you update the contact in every single case which is non-optimal and causes a major amount of maintenance code and risk in your C# code that should be managed by the datastore itself.
I would like EF Fluent instructions to allow turning on triggers and defining the triggers that are executed by default. These might be Azure Function triggers, or they could be native cosmosdb triggers, doesn't really matter, we just need to be able to turn them on. Further there should be an extension method that allows disabling them temporarily for batch operations etc.
Without this functionality you're not properly separating data store functions from data access functions.
Team notes: putting this on the backlog to track using triggers in Cosmos. Note that we currently have no plans to support creation of triggers for Cosmos in EF Core.
I'm not asking to create triggers. I'm asking to ensure that already created triggers actually fire, which they don't appear to at the moment.
Note to implementor: See how to run triggers
Any updates on this? We need to be able to execute triggers Pre/Post at time of insert/update.
@robrow01 This is currently in the Backlog milestone, meaning we aren't actively working on it.