DbContext is very slow when adding and deleting

前端 未结 2 1928
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 22:38

When using DbContext in a database-first scenario I found out that adding and deleting entities is very slow compared to ObjectContext. If adding 2000 entities and saving th

2条回答
  •  离开以前
    2020-12-07 23:31

    In EF6 you can now use AddRange and RemoveRange on DbSet.

    From to the documentation on the links:

    Note that if AutoDetectChangesEnabled is set to true (which is the default), then DetectChanges will be called once before {adding,deleting} any entities and will not be called again. This means that in some situations {Add,Remove}Range may perform significantly better than calling {Add,Remove} multiple times would do.

提交回复
热议问题