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

  • Home
  • SEARCH
  • 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 8859929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:09:59+00:00 2026-06-14T15:09:59+00:00

I have a table similar to below: Data { id varchar(50), pId uniqueidentifier ,

  • 0

I have a table similar to below:

Data {
    id varchar(50),
    pId uniqueidentifier ,
    fId uniqueidentifier ,
    xid uniqueidentifier,
    flag smallint 
}

The table contains a lot of duplicate rows since pId and fId is a 1:n relationship and fId to xId is a 1:n relationship too.

I want to query this table and populate a obj as below:

class P
{
    Guid id;
    List<F> fList; 
}

class F
{
    Guid id;
    List<X> xList; 
}


class X
{
    Guid id;
    byte flag; 
}

I am learning Linq. Any solutions using Linq to populate class P from the table would be helpful.

Thanks!

  • 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-14T15:10:00+00:00Added an answer on June 14, 2026 at 3:10 pm

    This query will return IEnumerable<P> (not sure about converting smallint to boolean but other stuff should work)

    var query = from p in context.Data
                group p by p.pId into gp
                select new P()
                {
                    id = gp.Key,
                    fList = (from f in gp
                             group f by f.fId into gf
                             select new F()
                             {
                                 id = gf.Key,
                                 xList = gf.Select(x => new X() { id = x.xid, 
                                                                  flag = x.flag })
                                           .ToList()
                             }).ToList()
                };
    

    Comments:

    gp will contain all rows corresponding to some pId, in other words – it returns all fId, which related to pId.

    gf will contain all rows from previous result which relate to some fId (i.e. all xids related to fId)

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

Sidebar

Related Questions

I have a table with data similar to below: Group TimePoint Value 1 0
I have a table similar to below in sql server 2005 date_column | field1
I have a data.table object similar to this one library(data.table) c <- data.table(CO =
I have 1 table with similar data: CustomerID | ProjectID | DateListed | DateCompleted
I have a table with a Name field containing data similar to the following:
I have a data structure similar to the following picture. Table A has_many Table
I have a query as below to find duplicates in my table which contains
I have an excel sheet where in the data looks similar to the table
I have a table with 692256 number of rows ,which has data similar to
I have a table similar to this +--+-----+----+ |ID|Entry|Exit| +--+-----+----+ |18|32154|NULL| +--+-----+----+ |19|NULL |NULL|

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.