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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:04:09+00:00 2026-05-22T16:04:09+00:00

PetaPoco has introduced Multi-POCO queries in experimental form (for now). As their blog post

  • 0

PetaPoco has introduced Multi-POCO queries in experimental form (for now). As their blog post suggests and the code it provides this looks nice and all in One-to-One relations when we load multi POCOs per row as long as they don’t repeat over the records.

What happens when at least one side is many relation? Actually example code is Many-to-One relational data.

Example code is clearly a Many-to-One relation. I haven’t tested any PetaPoco code but what does the provided code on the blog post do? Does every Article have their own User object instance even though some may be the same user or do they share the same user object instance?

And what about other Many relation types? How do they work of they work at all?

  • 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-22T16:04:09+00:00Added an answer on May 22, 2026 at 4:04 pm

    Usually I map these one-to-many queries myself like the following example.

    [TableName("Blogs"), PrimaryKey("BlogId")]
    public class Blog {
        public int BlogId {get;set;}
        public string Title {get;set;}
    
        [Ignore]
        public IList<Post> Posts {get;set;}
    }
    
    [TableName("Posts"), PrimaryKey("PostId")]
    public class Post {
        public int PostId {get;set;}
        public int BlogId {get;set;}
        public string Subject {get;set;}
        public string Content {get;set;}
    }
    
    public class FlatBlogPost {
        public int BlogId {get;set;}
        public string Title {get;set;}
        public int PostId {get;set;}
        public string Subject {get;set;}
        public string Content {get;set;}
    }
    

    There are two ways I could display a list of posts for one blog or without too much work, all blogs.

    1.Two queries –

    var Blog = Db.Query<Blog>(1);  
    var Posts = Db.Query<Post>("where BlogId = @0", 1);
    

    2.One query =

    var flat = Db.Query<FlatBlogPost>("select b.blogid, b.title, p.postid, p.subject, 
               p.content from blogs b inner join posts p on b.blogid = p.blogid where
               b.blogid = @0", 1);
    
    var blog = flat
        .GroupBy(x=> new { x.BlogId, x.Title })
        .Select(x=> new Blog {
            BlogId = x.Key.BlogId,
            Title = x.Key.Title,
            Posts = x.Select(y=> new Post{
                        PostId = y.PostId,
                        BlogId = x.Key.BlogId,
                        Subject = y.Subject,
                        Content = y.Content
                    }).ToList()
        });
    

    However usually in number 2 I would map directly from the FlatBlogPost object to my viewmodel for which I need to display the data.

    Update
    Check out these helpers which extend PetaPoco to support basic One-to-Many and Many-to-One queries. schotime.net/blog/index.php/2011/08/21/petapoco-one-to-many-and-many-to-one/ https://schotime.wordpress.com/2011/08/21/petapoco-one-to-many-and-many-to-one/

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

Sidebar

Related Questions

I have the following POCO's: [PetaPoco.TableName(Customer)] [PetaPoco.PrimaryKey(ID)] public class User { [Required(ErrorMessage = Please
I'm using PetaPoco T4 Template (http://www.hanselman.com/blog/T4TextTemplateTransformationToolkitCodeGenerationBestKeptVisualStudioSecret.aspx), It always converting table names, for example it
What is the proper way in PetaPoco to hydrate a POCO property that is
I'm using PETAPOCO make a list of generic objects that are then bound to
I'm using C# with TSQL and SQL Server 2005 I'm trying to use PetaPoco
I like the micro approach of Dapper, Massive, PetaPoco etc. and I like to
We'd like to get rid of NHibernate for something like Massive, PetaPoco, etc. but
I have installed petapoco RelationExtensions from NUGET and it`s firing error message: Error 4
I know I can log exceptions with PetaPoco thus: public override void OnException(Exception x)
I'm using the PetaPoco mini-ORM, which in my implementation runs stored procedures and maps

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.