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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:00:59+00:00 2026-06-16T06:00:59+00:00

I have my 2 models like below public class FItem { public FItem() {

  • 0

I have my 2 models like below

public  class FItem
        {
            public FItem() { }

            public int RecordId { get; set; }
            public int MarketId { get; set; }
            public string ItemName { get; set; }
            public string ItemFamily { get; set; }
            public string HoverFamily { get; set; }
            public string ItemDesc { get; set; }                

            public IEnumerable<FSubsystem> FSubsystems { get; set; }
       }

   public class FSubsystem
        {
            public FSubsystem() { }

            public int FSubsystemId { get; set; }
            public int RecordId { get; set; } //Foreign key
            public int supplierId { get; set; }
            public int SubSystemTypeId { get; set; }
            public double Percentage { get; set; }
            public double? Value { get; set; }
        }

 public class FReferences
 {
     public FReferences() { }

     public int RecordID { get; set; } //Foreign key
     public int SourceID { get; set; }
     public DateTime SourceDate { get; set; }
     public string Reference { get; set; } 
     public int? ReferenceID { get; set; }
 }

and I use dapper to fetch the data and put into objects . code is as belolw

using (var multi = mapperConnection.QueryMultiple("USP_FetchMarketRecords", parameters, (SqlTransaction)null, 1000000, CommandType.StoredProcedure))
            {
                    IEnumerable<MarketRecord.FItem> FItem = multi.Read<MarketRecord.FItem>().ToList();                        
                    IEnumerable<MarketRecord.FSubsystem> FSubsystem = multi.Read<MarketRecord.FSubsystem>().ToList();                        
            }

Now I want to get the subsystems for each record id and put them in FSubsystems property of Fitem . How can I do this ?

Here I am showing only one one to many relationship to FItem thats Fsubsystem . But I have many one to many tables to Fitem like FReferenc ,FUnit etc . For all foreign key is RecordId itelf.

Can this be done through linq query ? or should I use some diff technique ?

  • 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-16T06:01:00+00:00Added an answer on June 16, 2026 at 6:01 am

    Dapper doesn’t include anything built in to reconstruct parent/child relationships from different sets.

    You can probably generalize the scenario something like:

    static void ApplyParentChild<TParent, TChild, TId>(
        this IEnumerable<TParent> parents, IEnumerable<TChild> children,
        Func<TParent, TId> id, Func<TChild, TId> parentId,
        Action<TParent, TChild> action)
    {
        var lookup = parents.ToDictionary(id);
        foreach (var child in children)
        {
            TParent parent;
            if (lookup.TryGetValue(parentId(child), out parent))
                action(parent, child);
        }
    }
    

    so if we had:

    List<Parent> parents = new List<Parent> {
        new Parent { Id = 1 },
        new Parent { Id = 2 }
    };
    List<Child> children = new List<Child> {
        new Child { Id = 3, ParentId = 1},
        new Child { Id = 4, ParentId = 2},
        new Child { Id = 5, ParentId = 1}
    };
    

    You could use:

    parents.ApplyParentChild(children, p => p.Id, c => c.ParentId,
        (p,c) => p.Children.Add(c));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
I have a model called 'UserRoleHolder' like below. @Entity public class UserRoleHolder extends Model
I have a model like below: public class CreateStockcheckJobModel { [Engineer(true)] public EngineerModel Engineer
I have written two functions like below in my model class. public function fetchByUsername($username)
Let's say I have an async controller like that below ~ public class HomeController
I have a field in my model class like below: [ScaffoldColumn(false)] public DateTime DatePosted
i have a model say modela with a calculate field. like below class modelA
I have models like this: class Vendor(models.Model): title = models.CharField() class Product(models.Model): ... vendor
I have models like this: class IdfPracownicy(models.Model): nazwa = models.CharField(max_length=100) class IdfPracaOpinie(models.Model): nazwa =
So, say I have models like this: class Foo(Model): name = CharField(max_length=200) def latest_comment(self):

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.