Correct way to remove a many-to-many relationship via linq to sql?

前端 未结 3 1887
广开言路
广开言路 2021-01-20 19:48

Let\'s say we have two tables with a many-to-many relationship:

public class Left{ /**/ }

public class Right{ /**/ }

public class LeftRight{ /**/ }
         


        
3条回答
  •  面向向阳花
    2021-01-20 20:45

    Personally, I'd replace

    left.LeftRrights.Remove(relation.First());
    

    with

    Db.LeftRights.DeleteAllOnSubmit(relation)
    

    because it seems more obvious what's going to happen. If you are wondering what the behaviour of ".Remove" is now, you'll be wondering anew when you look at this code in 6 months time.

提交回复
热议问题