Is EF "aware" of relationships for Insert and Delete

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
KW
Posts: 125
Joined: Tue 19 Feb 2008 19:12

Is EF "aware" of relationships for Insert and Delete

Post by KW » Wed 18 Jan 2017 01:21

Given:

Code: Select all

public class Blog
{
    public int BlogId { get; set; }
    public string Url { get; set; }

    public List<Post> Posts { get; set; }
}

public class Post
{
    public int PostId { get; set; }
    public string Title { get; set; }
    public string Content { get; set; }

    public Blog Blog { get; set; }
}
Let's say Blogs 'Update' and 'Delete' relationship to Posts is set to 'STRICT'.

If you mark the entity object Blog and Posts as deleted and hit save, is the framework smart enough to know you need to delete the Posts first before it deletes the Blog?

Conversely, if you Add a Blog and Post to a DBCONTEXT, does it know that it needs to create the Blog first before it creates the Posts?

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: Is EF "aware" of relationships for Insert and Delete

Post by Shalex » Fri 20 Jan 2017 09:14

KW wrote:If you mark the entity object Blog and Posts as deleted and hit save, is the framework smart enough to know you need to delete the Posts first before it deletes the Blog?
Yes, it is.
KW wrote:Conversely, if you Add a Blog and Post to a DBCONTEXT, does it know that it needs to create the Blog first before it creates the Posts?
Yes, it does.

Post Reply