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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:56:50+00:00 2026-05-29T09:56:50+00:00

I have the following tables Client Table and Product Table ID Name ClientProduct Table

  • 0

I have the following tables

Client Table and Product Table

ID
Name

ClientProduct Table

ID
ClientID
ProductID

Product class

 private int id;
    public int ID
    {
        get { return id; }
        set { id = value; }
    }
     protected string name;

    public Product () { }

    public Product (string name)
    {
        this.name = name;
    }

    public Product (string name)
    {
        this.name = name;
    }   
    public string Name
    {
        get { return name; }
        set { name = value; }
    }

Client class

     private int id;
    public int ID
    {
        get { return id; }
        set { id = value; }
    }
     protected string name;

    public Client () { }

    public Client (string name)
    {
        this.name = name;
    }

    public Client (string name)
    {
        this.name = name;
    }   
    public string Name
    {
        get { return name; }
        set { name = value; }
    }

ClientProduct class

        protected Client client;
    protected Product product;

    public ClientProduct  () { }

    public ClientProduct  (Client client,  Product product)
    {
        this.client= client;
        this.product= product;
    }

    public Client client        {
        get { return client; }
        set { client= value; }
    }

    public Product product      {
        get { return product; }
        set { product= value; }
    }

How can I do the following in petaPOCO?

    public static System.Collections.Generic.IList<ClientProduct> LoadForClient(Client client)
    {
        if (null != client)
            return Load("ClientID = " + client.ID);
        else
            return null;
    }

such that I can have list of all products for that client that I will later used in my view as

 private void LoadProducts(Client client )
    {
        Products = ClientProduct.LoadForClient(client)
            .Select(x => x.Product.Name)
            .OrderBy(x => x).ToArray();
    }
  • 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-29T09:56:51+00:00Added an answer on May 29, 2026 at 9:56 am

    The 1:M and M:1 relationships seem like what you’re after
    http://www.toptensoftware.com/Articles/115/PetaPoco-Mapping-One-to-Many-and-Many-to-One-Relationships

    You can define a custom relator callback; Brad’s example for two tables (if your products mapped directly to the client) would look something like this:

    var posts = db.Fetch<Product, Client, ClientProduct>(
        (p,c)=> { p.client_obj = c; return p; },
        @"SELECT * FROM Product
        LEFT JOIN Client ON Product.clientId = Client.id ORDER BY Product.clientId 
        ");
    

    I realize your dealing with a M:M relationship so you would need to update the above to map across the three objects, but the concept is the same. The key is that your 3rd argument in the call (ClientProduct) represents the joined row, and you can then reference the Client and/or Products directly from the single list.

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

Sidebar

Related Questions

I have the following database tables: TABLE dbo.Client ( ClientId PK uniqueidentifier , ClientNames
I have the following tables: table A: FOO (PK) | CLIENT (PK) table B:
I have the following tables setup in a MySQL database: Client: id name Session:
Lets say I have table with following columns 1. Client - string. 2. Profit
I have the following tables in MySQL: team: id, name, [more stuff] person: id,
I have the following tables in SQL Server 2005 ReceiptPoint: ID (PK), Name GasIndexLocation:
I have two tables as follows: CREATE TABLE customer ( id INT NOT NULL
I have the following model. from django.db import models class Client(models.Model): postcode = models.CharField(max_length=10)
I have following tables questions -> id, question_data, user_id users -> id, fname, lname
I have the following tables in my database that have a many-to-many relationship, which

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.