dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.65k stars 3.15k forks source link

Cosmos: Support trigger execution #19944

Open JohnGalt1717 opened 4 years ago

JohnGalt1717 commented 4 years ago

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.

ajcvickers commented 4 years ago

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.

JohnGalt1717 commented 4 years ago

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.

AndriySvyryd commented 4 years ago

Note to implementor: See how to run triggers

robrow01 commented 3 years ago

Any updates on this? We need to be able to execute triggers Pre/Post at time of insert/update.

AndriySvyryd commented 3 years ago

@robrow01 This is currently in the Backlog milestone, meaning we aren't actively working on it.