How to disable cascade insertion in EF Core

Zahid Mustafa 1 Reputation point

I am facing an issue in EF Core 5.0, When i am inserting the Data in Parent table child entries are auto inserted How to disable it

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
512 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,496 Reputation points

    Hi ZahidMustafa-9099,
    First, there is no definition of cascade insertion.
    And you can try to use the EntityEntry.State property to set the state of just a single entity.

    context.Entry(your entity).State = EntityState.Modified.  

    Please refer to this document.
    More suggestions have been provided in this thread you can refer to.
    Best Regards,
    Daniel Zhang

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments