dotnet / dotnet/EntityFramework.Docs

Update Trigger bug

Open
#4,324 1 comment 0 reactions 0 assignees View on GitHub
area-model-building
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

The update trigger for updating timestamps doesn't work for multi-row inserts.

Should probably be something like:

```sql
CREATE TRIGGER [dbo].[Blogs_UPDATE] ON [dbo].[Blogs]
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;

IF ((SELECT TRIGGER_NESTLEVEL()) > 1) RETURN;

UPDATE dbo.Blogs
SET LastUpdated = GETDATE()
FROM INSERTED
WHERE dbo.Blogs.BlogId = INSERTED.BlogId
END
```

---
#### Document Details

⚠ *Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.*

* ID: 97d622b2-1e4b-4d76-b3df-fefaa5ba99cb
* Version Independent ID: ec833af2-275e-981f-689f-8c65edfc00cd
* Content: [Generated Values - EF Core](https://learn.microsoft.com/en-us/ef/core/modeling/generated-properties?tabs=data-annotations)
* Content Source: [entity-framework/core/modeling/generated-properties.md](https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/modeling/generated-properties.md)
* Product: **entity-framework**
* Technology: **entity-framework-core**
* GitHub Login: @AndriySvyryd
* Microsoft Alias: **avickers**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.