Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8409047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:48:02+00:00 2026-06-09T23:48:02+00:00

My application has be entity model as below and use Dapper public class Goal

  • 0

My application has be entity model as below and use Dapper

public class Goal
{
    public string Text { get; set; }
    public List<SubGoal> SubGoals { get; set; }
}

public class SubGoal
{
    public string Text { get; set; }
    public List<Practise> Practices { get; set; }
    public List<Measure> Measures { get; set; }
}

and has a repository as below

public interface IGoalPlannerRepository
{
    IEnumerable<Goal> FindAll();
    Goal Get(int id);
    void Save(Goal goal);
}

I came across two scenarios as below

  1. While retrieving data (goal entity), it needs to retrieve all the related objects in hierarchy (all subgoals along with practices and measures)
  2. When a goal is saved all the related data need to be inserted and/or updated

Please suggest is there a better way to handle these scenarios other than “looping through” the collections and writing lots and lots of SQL queries.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:48:03+00:00Added an answer on June 9, 2026 at 11:48 pm

    The best way to do large batch data updates in SQL using Dapper is with compound queries.

    You can retrieve all your objects in one query as a multiple resultset, like this:

    CREATE PROCEDURE get_GoalAndAllChildObjects
        @goal_id int
    AS
    SELECT * FROM goal WHERE goal_id = @goal_id
    SELECT * FROM subgoals WHERE goal_id = @goal_id
    

    Then, you write a dapper function that retrieves the objects like this:

    using (var multi = connection.QueryMultiple("get_GoalAndAllChildObjects", new {goal_id=m_goal_id})) {
        var goal = multi.Read<Goal>();
        var subgoals = multi.Read<SubGoal>();
    }
    

    Next comes updating large data in batches. You do that through table parameter inserts (I wrote an article on this here: http://www.altdevblogaday.com/2012/05/16/sql-server-high-performance-inserts/ ). 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.

    This is super high performance and about as optimized as you can get, plus the code isn’t too complex.

    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 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use Dynamic Data with a entity model that has Abstract class
I am developing an asp.net mvc application, which has these enity classes: public class
My application has an Entity Framework model containing a many-to-many relationship like the following:
I am creating a Core Data application where: category entity has the following attributes
I'm trying to create ASP.NET MVC Application with Entity Framework, which has One to
I have an ASP.NET application using an entity framework model. In an import routine,
I created a new Entity Framework model from a database. This database has a
I have an SecurityGroup entity witch has Memebers and Application properties. Application is a
I am working on an ASP.NET MVC application which has a model for a
I'm writing an application that has POCO Entity Framework data access on the server.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.