Why would reusing a DataContext have a negative performance impact?

前端 未结 4 1737
终归单人心
终归单人心 2020-12-14 10:02

After a fair amount of research and some errors, I modified my code so that it creates a new DataContext each time the database is queried or data is inserted. And the data

4条回答
  •  生来不讨喜
    2020-12-14 10:51

    Even with a clustered index, in-memory lookup will always be faster than a database query--except in edge cases, like a 386 vs. a Cray--even if you factor out network-related delays.

    I would guess the degradation has to do with the DataContext's handling of entities that it tracks: reusing a context will continually increase the number of tracked entities, and the call to SaveChanges may end up requiring more time.

    Again, that's a guess--but it's where I'd start looking.

提交回复
热议问题