Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best way to do large batch data updates in SQL using Dapper is with compound queries.</p> <p>You can retrieve all your objects in one query as a multiple resultset, like this:</p> <pre><code>CREATE PROCEDURE get_GoalAndAllChildObjects @goal_id int AS SELECT * FROM goal WHERE goal_id = @goal_id SELECT * FROM subgoals WHERE goal_id = @goal_id </code></pre> <p>Then, you write a dapper function that retrieves the objects like this:</p> <pre><code>using (var multi = connection.QueryMultiple("get_GoalAndAllChildObjects", new {goal_id=m_goal_id})) { var goal = multi.Read&lt;Goal&gt;(); var subgoals = multi.Read&lt;SubGoal&gt;(); } </code></pre> <p>Next comes updating large data in batches. You do that through table parameter inserts (I wrote an article on this here: <a href="http://www.altdevblogaday.com/2012/05/16/sql-server-high-performance-inserts/" rel="nofollow">http://www.altdevblogaday.com/2012/05/16/sql-server-high-performance-inserts/</a> ). Basically, you create one table for each type of data you are going to insert, then write a procedure that takes those tables as parameters and write them to the database.</p> <p>This is super high performance and about as optimized as you can get, plus the code isn't too complex.</p> <p>However, I need to ask: is there any point to keeping "subgoals" and all the other objects relational? One easy alternative is to create an XML or JSON document that contains your goal and all its child objects serialized into text, and just save that object to the file system. It's unbelievably high performance, very simple, very extensible, and takes very little code. The only downside is that you can't write a SQL statement to browse across all subgoals with a bit of work. Consider it - it might be worth a thought ;)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload