dotnet / dotnet/EntityFramework.Docs

I think there is a inaccuracy in the example in the "Removing relationships" section.

Open Beginner friendly
#5,455 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

### Type of issue

Missing information

### Description

I think there is a inaccuracy in the example in the "Removing relationships" section.

Before the example you say "In the following example, a cascade delete is configured on the relationship
between Blog and Post, so the post entity is deleted from the database."

But in this example, you are simply loading and deleting the dependent entity, and this is not how cascading delete works.

A cascading delete occurs as if you were deleting the blog entity.

To avoid confusing people, just replace the text with an example. For example "In the following example, the Post entity with relation with a Blog is deleted from database."

I think a good example would look like this:

```cs
static async Task RemoveARelatedEntity(BloggingContext context)
{
Blog? blog = await context.Blogs.Include(b => b.Posts).FirstOrDefaultAsync();
Post? post = blog?.Posts.FirstOrDefault();

if(post is Post postForDelete)
{
blog?.Posts.Remove(postForDelete);
}
var count = await context.SaveChangesAsync();

Console.WriteLine(count);
}
```

### Page URL

https://learn.microsoft.com/en-us/ef/core/saving/related-data#removing-relationships

### Content source URL

https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/saving/related-data.md

### Document Version Independent Id

c7517e7d-f011-a24c-53da-913771913998

### Platform Id

2ee82799-795d-007e-9344-9fe1bda2c30a

### Article author

@SamMonoRT

Contributor guide

Open the contributing guide

Research direction

Open entity-framework/core/saving/related-data.md and read the “Removing relationships” section around the linked example. Update the explanatory text and example so they accurately describe deleting a related Post rather than a cascade delete triggered by deleting the Blog. Done means the documentation no longer mischaracterizes the operation and the example matches the explanation.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.