EntityCollection Clear() and Remove() methods

前端 未结 5 1983
隐瞒了意图╮
隐瞒了意图╮ 2021-01-04 04:53

What is the right way to delete all of the collection items of an EF entity? In the code below, DocumentItems is the collection of related document items for a document. Thi

5条回答
  •  失恋的感觉
    2021-01-04 05:38

    Yeah, a year old, but on a minor note... since DeleteObject takes one parameter, which is the same type as the argument for the lambda expression, you can just use:

    entityCollection.ToList().ForEach(ctx.DeleteObject);
    

    I am not sure if VB supports a similar syntax, though. Anyone?

提交回复
热议问题