none
Can EntityFramework send all queries in one shot? RRS feed

  • Question

  • We have a system where we have 8 tables. In each context we will either insert / update few of the 8 tables. As I see in the logs, entity framework is sending multiple queries one by one in sequence to update each table. Is there a way that entity framework to send all queries in one go to the database and get the status? In my view this will improve the performance by whole lot as we are avoiding the network calls.

    FYI, our system is a multi threaded where each thread has its own context to update these 8 tables. Since there are multiple queries to DB for a single context (i.e., thread) it is becoming very slow.

    FYI, If I have a single thread then context saving is taking 7 ms. But If I have few hundreds of threads (each thread having its own context and try to save to DB) the context save on an average is taking 300 ms. This can be the DB issue and also multiple network calls (sql quereies) per each thread.. We are confident that the data and indexes are correct on the DB side so we suspect the network delays here. In DB we have lock escalation set to auto. We suspect that the DB delay is due to the lock contention when we run multiple threads in parallel.

    Any suggestions are welcome and much appreciated.. Thanks in advance...


    • Edited by Balu1202 Wednesday, November 25, 2015 2:31 PM
    Wednesday, November 25, 2015 2:29 PM

Answers

  • this

    this

    Or you could try StoredProcedures (although if you use them for manipulations (insert update delete), you have to reload all of the Entries in the Context)


    • Edited by MDeero Wednesday, November 25, 2015 3:53 PM
    • Marked as answer by DotNet WangModerator Thursday, December 3, 2015 1:51 AM
    Wednesday, November 25, 2015 3:52 PM

All replies

  • this

    this

    Or you could try StoredProcedures (although if you use them for manipulations (insert update delete), you have to reload all of the Entries in the Context)


    • Edited by MDeero Wednesday, November 25, 2015 3:53 PM
    • Marked as answer by DotNet WangModerator Thursday, December 3, 2015 1:51 AM
    Wednesday, November 25, 2015 3:52 PM
  • No luck?

    Please elaborate.

    Got what you need?

    Please mark an answere so the Thread can be closed.

    Friday, November 27, 2015 6:32 AM
  • Taking a step back: May I ask why, exactly, you have hundreds of threads all updating the same data?

    Hundreds of threads sounds rather excessive. Multi-threading obviously has its uses, but after a point, switching thread contexts takes up more CPU resources than its worth.

    Friday, November 27, 2015 10:19 AM