-
Notifications
You must be signed in to change notification settings - Fork 2k
Document Cosmos trigger execution support #5114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AndriySvyryd
merged 7 commits into
live
from
copilot/fix-f72ae271-1f04-4552-9c07-76e8c2b1a7cb
Oct 3, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a224558
Initial plan
Copilot e821262
Add documentation for Cosmos trigger execution
Copilot 5222db1
Address review feedback: Update version to 10.0, clarify server-side …
Copilot c7a215c
Configure project for .NET 10 and uncomment HasTrigger methods
Copilot f515718
Move global.json to samples/ folder and remove Cosmos README.md
Copilot aa59831
Update ms.date in modeling.md header to 09/26/2024
Copilot ab06499
Move Database triggers section to bottom of page
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| using Microsoft.Azure.Cosmos.Scripts; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Cosmos.ModelBuilding; | ||
|
|
||
| public static class TriggerSample | ||
| { | ||
| public static async Task ConfigureTriggers() | ||
| { | ||
| var contextOptions = new DbContextOptionsBuilder<TriggerContext>() | ||
| .UseCosmos("https://localhost:8081", "account-key", "sample"); | ||
|
|
||
| using var context = new TriggerContext(contextOptions.Options); | ||
|
|
||
| // Ensure database is created | ||
| await context.Database.EnsureCreatedAsync(); | ||
|
|
||
| // Create a new product - this will trigger the PreInsertTrigger | ||
| var product = new Product | ||
| { | ||
| Id = 1, | ||
| Name = "Sample Product", | ||
| Price = 19.99m, | ||
| Category = "Electronics" | ||
| }; | ||
|
|
||
| context.Products.Add(product); | ||
| await context.SaveChangesAsync(); | ||
|
|
||
| // Update the product - this will trigger the UpdateTrigger | ||
| product.Price = 24.99m; | ||
| await context.SaveChangesAsync(); | ||
|
|
||
| // Delete the product - this will trigger the PostDeleteTrigger | ||
| context.Products.Remove(product); | ||
| await context.SaveChangesAsync(); | ||
| } | ||
| } | ||
|
|
||
| public class TriggerContext : DbContext | ||
| { | ||
| public TriggerContext(DbContextOptions options) : base(options) { } | ||
|
|
||
| public DbSet<Product> Products { get; set; } | ||
|
|
||
| protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
| { | ||
| modelBuilder.Entity<Product>(entity => | ||
| { | ||
| entity.HasPartitionKey(p => p.Category); | ||
|
|
||
| #region TriggerConfiguration | ||
| // 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); | ||
| #endregion | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| public class Product | ||
| { | ||
| public int Id { get; set; } | ||
| public string Name { get; set; } = null!; | ||
| public decimal Price { get; set; } | ||
| public string Category { get; set; } = null!; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
AndriySvyryd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "sdk": { | ||
| "version": "10.0.100-rc.1.25451.107" | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.