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 6136111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:33:47+00:00 2026-05-23T17:33:47+00:00

I have a list objects I use to fill using Petapoco. The class properties

  • 0

I have a list objects I use to fill using Petapoco.

The class properties and names are maching the database schema. The main class is Issue, and it is related to two other classes which names and properties matches the database schema too : Condition and SeverityLevel.

public class Issue
{
    public int Id { get; set; } // Primary key

    /* Some properties... */
    public DateTime? CreatedOn { get; set; }
    public string CreatedBy { get; set; }
    public DateTime? ModifiedOn { get; set; }
    public string ModifiedBy { get; set; }

    /* ... */

    // Related source and target conditions
    [PetaPoco.Ignore]
    public Condition SourceCondition { get; set; }

    [PetaPoco.Ignore]
    public Condition TargetCondition { get; set; }

    // Related severity level
    [PetaPoco.Ignore]
    public SeverityLevel CurrentSeverityLevel { get; set; }
}

public class Condition
{
    public int Id { get; set; } // Primary Key
    public string Description  { get; set; }
}

public class SeverityLevel
{
    public int Id { get; set; } // Primary key
    public string Description { get; set; }
    public string HexColorDisplay { get; set; }
}

Actually, when I retrieve a list of Issues, I am using the multimapping feature to retrieve Issue list and related SeverityLevel using a single command :

var Results = Db.Fetch<Issue, SeverityLevel, Issue>(
    (i, sl) => { 
        i.CurrentSeverityLevel = sl;
        return i;
    },
    "SELECT /* ..shortened.. */ FROM Issue " + 
    "LEFT JOIN SeverityLevel ON SeverityLevel.Id = Issue.SeverityLevelId " + 
    "WHERE Issue.Id=@0", issueId);

Now, because Petapoco does not seems to handle multiple JOINS, I need to do a second step to attach SourceCondition and TargetCondition to each Issue I retrieved.

To do so, I could either :

  • attach the Source and the Target condition after a Read, in a foreach loop,
  • or retrieve the whole list of Condition, then attach then to each Issue using the same kind of for-each.

For now, I am using the second solution because there is a limited set of Condition in the database.

Anyway, it sounds a bit heavy to me to do this way, because it requires almost as many queries to be done as JOINED tables are added.

I wonder if I could achieve to make work something like this :

var Results = Db.Fetch</* ????? */>(
    /* ???? */
    "SELECT /* ..shortened.. */ FROM Issue " + 
    "LEFT JOIN SeverityLevel ON SeverityLevel.Id = Issue.SeverityLevelId " + 
    "LEFT JOIN Condition Con1 ON Con1.Id = Issue.SourceConditionId " + 
    "LEFT JOIN Condition Con2 ON Con2.Id = Issue.TargetConditionId " + 
    "WHERE Issue.Id=@0", issueId);

Dear Petapoco users, dear Petapoco author, is this a way to handle this ?

Could I use Dapper to deals with this instead (if it can…), appart I absolutely want to keep Petapoco for my update/insert operations ?

  • 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-05-23T17:33:48+00:00Added an answer on May 23, 2026 at 5:33 pm

    This should be able to be done.

    var Results = Db.Fetch<Issue, SeverityLevel, Condition, Condition, Issue>(
        (i, sl, c1, c2) => { 
            i.CurrentSeverityLevel = sl;
            i.SourceCondition = c1;
            i.TargetCondition = c2;
            return i;
        },
        "SELECT Issue.*, SeverityLevel.*, Con1.*, Con2.* FROM Issue " + 
        "LEFT JOIN SeverityLevel ON SeverityLevel.Id = Issue.SeverityLevelId " + 
        "LEFT JOIN Condition Con1 ON Con1.Id = Issue.SourceConditionId " + 
        "LEFT JOIN Condition Con2 ON Con2.Id = Issue.TargetConditionId " + 
        "WHERE Issue.Id=@0", issueId);
    

    I have not tested this.
    I am also working on a way to automate this.

    It’s really important that the columns selected are in the same order that the parameter types are.

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

Sidebar

Related Questions

I have a List of objects (string filename, BitmapImage image) to use as a
Let's say I have a list of User objects with two properties...ID and Name
I have an object of type list from which I wish to use to
I have List objects which are shown like this: www.mysite.com/lists/123 Where 123 is the
I have 2 List objects: List<int> lst1 = new List<int>(); List<int> lst2 = new
I have a list of objects I wish to sort based on a field
I have a list of objects, each containing an Id, Code and Description. I
I have IQueryable list of objects of type T which I want to transform
I have a list of objects (for the sake of example, let's say 5).
I have a list of objects and I want to reorder them randomly on

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.