locked
Just need quick clarification on Remove EF6 RRS feed

  • Question

  • User1034446946 posted

    Hi

    I have a complex model with 3 tiers

    I want to Detach the 3rd tier from the second tier (remove the navigation link) but not delete them from the database

    then I want remove the 2nd tier from the database completely

    I am using EF6, how do I go about it

    Is it something like

    foreach(var one in OneModel)
    {
    foreach(var two in one.ModelTwo)
    {
    two.ThreeModel.Clear();//This detaches the third models
    }
    two.Remove()//This detaches the secondmodel
    }
    }

    Any information would be appriciated.

    Monday, April 23, 2018 2:13 AM

Answers

  • User1034446946 posted

    i was right in the op

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 23, 2018 2:48 PM

All replies

  • User1120430333 posted

    What are you talking about?

    Is it this?

    Parent has 1-2-many and each many has 1-2-many.

    Monday, April 23, 2018 9:05 AM
  • User1034446946 posted
    public OneModel
    {
    public int Id {get;set;}
    public string someField{get;set;}
    public List<TwoModel> TwoModel {get;set;}
    }
    
    public TwoModel
    {
    public int Id {get;set;}
    public string someField{get;set;}
    public int OneModelId {get;set;}
    public List<ThreeModel> ThreeModel {get;set;}
    }
    
    public TwoModel
    {
    public int Id {get;set;}
    public int TwoModelId {get;set;}
    public string someField{get;set;}
    }

    So both have many to 1 relationships,

    I so a db call which calls one model, which includes two and three model

     and I want seperate all the models and keep model one and three and delete all two models.

    (I have cascading deletes switched off)

    any suggestions

    Monday, April 23, 2018 11:37 AM
  • User1034446946 posted

    i was right in the op

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 23, 2018 2:48 PM