Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 26, 2025

Adds documentation for the new Azure Cosmos DB trigger execution feature introduced in EF Core 10.0, following the implementation in dotnet/efcore#36505.

Changes

Documentation (entity-framework/core/providers/cosmos/modeling.md)

  • Added new "Database triggers" section explaining pre- and post-trigger support
  • Documented the HasTrigger method with parameters and usage examples
  • Included important security warning about server-side execution but lack of enforcement
  • Added version note indicating the feature requires EF Core 10.0+
  • Updated ms.date to reflect current documentation date
  • Positioned section at the bottom of the page for appropriate emphasis

Sample Code (samples/core/Cosmos/ModelBuilding/TriggerSample.cs)

  • Created comprehensive sample demonstrating trigger configuration
  • Shows configuration for different trigger types (Pre/Post) and operations (Create/Replace/Delete)
  • Includes complete database operations (Add, Update, Delete, SaveChanges) that trigger execution
  • Updated to use EF Core 10.0.0-rc.1.25451.107 with uncommented, compilable trigger methods

Project Configuration

  • Added samples/global.json specifying .NET 10 SDK version 10.0.100-rc.1.25451.107
  • Updated Cosmos sample project to target net10.0 framework
  • Updated NuGet package reference to EF Core 10.0.0-rc.1.25451.107

Key Points Documented

The documentation emphasizes that:

  • Triggers are executed server-side by Azure Cosmos DB when EF Core performs operations, but are not enforced - operations can be performed without running triggers if accessing the database directly
  • Triggers should not be used for security-related functionality like authentication or auditing
  • Triggers must be pre-created in Azure Cosmos DB before EF Core can execute them
  • The trigger name in EF Core configuration must match the trigger name in Azure Cosmos DB

Example Usage

modelBuilder.Entity<Product>(entity =>
{
    entity.HasPartitionKey(p => p.Category);
    
    // Configure pre-trigger for create operations
    entity.HasTrigger("PreInsertTrigger", TriggerType.Pre, TriggerOperation.Create);
    
    // Configure post-trigger for delete operations
    entity.HasTrigger("PostDeleteTrigger", TriggerType.Post, TriggerOperation.Delete);
    
    // Configure trigger for replace operations
    entity.HasTrigger("UpdateTrigger", TriggerType.Pre, TriggerOperation.Replace);
});

Fixes #5080


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] Document Cosmos trigger execution Document Cosmos trigger execution support Sep 26, 2025
Copilot finished work on behalf of AndriySvyryd September 26, 2025 20:18
@Copilot Copilot AI requested a review from AndriySvyryd September 26, 2025 20:18
…execution, remove xref link, and enhance sample code

Co-authored-by: AndriySvyryd <[email protected]>
Copilot finished work on behalf of AndriySvyryd September 26, 2025 23:22
@Copilot Copilot AI requested a review from AndriySvyryd September 26, 2025 23:36
Copilot finished work on behalf of AndriySvyryd September 26, 2025 23:36
@AndriySvyryd AndriySvyryd marked this pull request as ready for review September 26, 2025 23:58
@AndriySvyryd AndriySvyryd requested a review from a team September 26, 2025 23:58
@AndriySvyryd AndriySvyryd self-requested a review September 30, 2025 16:54
@Copilot Copilot AI requested a review from AndriySvyryd September 30, 2025 19:21
Copilot finished work on behalf of AndriySvyryd September 30, 2025 19:21
@AndriySvyryd
Copy link
Member

@copilot Update progress by changing the PR description to a nicely formatted summary of the changes

Copy link
Contributor Author

Copilot AI commented Sep 30, 2025

@copilot Update progress by changing the PR description to a nicely formatted summary of the changes

Updated the PR description with a nicely formatted summary of all changes, organized by category with clear sections for documentation, sample code, and project configuration.

Copilot finished work on behalf of AndriySvyryd September 30, 2025 23:57
Copilot finished work on behalf of AndriySvyryd October 3, 2025 20:42
@AndriySvyryd AndriySvyryd merged commit b3ecb10 into live Oct 3, 2025
6 checks passed
@AndriySvyryd AndriySvyryd deleted the copilot/fix-f72ae271-1f04-4552-9c07-76e8c2b1a7cb branch October 3, 2025 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document Cosmos trigger execution
3 participants