0

We have switched ORM framework from XPO to Entity Framework. We have been satisfied with the performance working on XPO.

Our algorithms contain many read operations on foreign key related collections thus we need these up to date and also there are bunch of operations which invoke DetectChanges method (we have AutoDetectChanges enabled). Each call of DetectChanges has very poor performance.

Second matter is Delete method which requires subsequent call of SaveChanges to have collections updated – it is also very slow.

Is there any possibility to disable AutoDetectChanges holding collections updated and improve performance or any other solution to improve performance?

example project github link

  • 1
    We have no way of knowing what your code does or what it did before the change. Both ORMs generate SQL statements, so any questions about performance are actually questions about the generated SQL statements, the table schemas and indexes. WIthout either source code or queries and execution plans, it's impossible to answer this question – Panagiotis Kanavos Feb 17 '20 at 14:14
  • `Each call of DetectChange` ??? Why call this at all? EF tracks changes itself. `is Delete method which requires subsequent call of SaveChanges` no it doesn't. `SaveChanges` persists *all* changes. If the code calls it multiple times, it has a very serious bug that prevents EF from working as it should, in a disconnected manner – Panagiotis Kanavos Feb 17 '20 at 14:16
  • Have you tried to implement the generic repository *anti*pattern perhaps, with explicit transactios to re-implement the UoW behavior of DbContext that was lost due to the multiple SaveChanges calls? – Panagiotis Kanavos Feb 17 '20 at 14:17
  • Example: Create object of type A related with B. Then reference A in collection on B. To see A on that collection i have to call detectchanges. In case of delete i have to call savechanges to remove A from collection on B. – Maciej Dzierżak Feb 18 '20 at 06:35
  • No you don't. SaveChanges will detect and perform all those changes by itself. You don't need to call `DetectChanges` at all, and `SaveChanges` only needs to be called once. There's still no code, so it's impossible to guess what else may be wrong – Panagiotis Kanavos Feb 18 '20 at 14:23
  • I have created example project representing problem on github. URL in description – Maciej Dzierżak Feb 20 '20 at 11:38
  • It also shows some pretty bad usage of `DbContext`. That class is *not* meant to be cached. It's not a connection (which doesn't need to be cached either). It's meant to be used inside a `using` block and disposed as soon as it's no longer needed. `AlgorithmBase` can only cause bugs – Panagiotis Kanavos Feb 20 '20 at 11:49
  • please someone look at that !! https://stackoverflow.com/questions/66647272/threadsafedatalayer-and-idatalayer-devexpress-xpo-cant-map-classinfo-to-same-ta –  Mar 21 '21 at 02:51

0 Answers0