Group child list into single parent object - AdventureWorks query - Lambda ExpressionSorting a list using Lambda/Linq to objectsLeft join in Linq?convert a list of objects from one type to another using lambda expressionUsing Linq to group a list of objects into a new grouped list of list of objectsLinq doing a group in a lambda subselectObject grouping with linq or lambda expressionquery list with linq lambda expressionsUsing LINQ to group a list of objectsSelecting decimal and string anonymous types in single LINQ query that's groupedLeft join in linq to entities null error

Would it be fair to use 1d30 (instead of rolling 2d20 and taking the higher die) for advantage rolls?

Does a non-singular matrix have a large minor with disjoint rows and columns and full rank?

Non-African Click Languages

Why is so much ransomware breakable?

What is the velocity distribution of the exhaust for a typical rocket engine?

Is it standard to have the first week's pay indefinitely withheld?

How could it be that 80% of townspeople were farmers during the Edo period in Japan?

Usage of the relative pronoun "dont"

Why does the U.S military use mercenaries?

Solenoid fastest possible release - for how long should reversed polarity be applied?

What color to choose as "danger" if the main color of my app is red

How can we delete item permanently without storing in Recycle Bin?

Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?

Why is vowel phonology represented in a trapezoid instead of a square?

Why do academics prefer Mac/Linux?

Why are lawsuits between the President and Congress not automatically sent to the Supreme Court

Why do galaxies collide?

How long do Aarakocra live?

What formula to chose a nonlinear formula?

Cross products/avoiding using your hand for the right hand rule in E and M

How can I make dummy text (like lipsum) grey?

What is this rubber on gear cables

Cannot remove door knob -- totally inaccessible!

Working hours and productivity expectations for game artists and programmers



Group child list into single parent object - AdventureWorks query - Lambda Expression


Sorting a list using Lambda/Linq to objectsLeft join in Linq?convert a list of objects from one type to another using lambda expressionUsing Linq to group a list of objects into a new grouped list of list of objectsLinq doing a group in a lambda subselectObject grouping with linq or lambda expressionquery list with linq lambda expressionsUsing LINQ to group a list of objectsSelecting decimal and string anonymous types in single LINQ query that's groupedLeft join in linq to entities null error






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am working with the AdventureWorks database and I am using the following query :



 SELECT c.CustomerID, c.AccountNumber, soh.SalesOrderID, soh.SalesOrderNumber, sod.UnitPrice, sod.ProductID, p.Name
FROM Sales.SalesOrderHeader soh
inner join sales.SalesOrderDetail sod on soh.SalesOrderID = sod.SalesOrderID
inner join sales.Customer c on c.CustomerID = soh.CustomerID
inner join Production.Product p on p.ProductID = sod.ProductID


I have code already that populates the data like this just as it comes back:
enter image description here



Based on that I am wanting to merge the child list objects into a single parent to end up with a one to many structure if that makes sense.



As of right now I am hoping to use a lambda expression to do this. I have tried the following code but I don't want to have to specify --> o.CustomerID, o.AccountNumber in the group by because i would have to specify ALL the properties of my Customer class to have access to the final select as you can see in the code.



 .GroupBy(o => new o.CustomerID, o.AccountNumber ).Select(group => new Customer2

CustomerID = group.Key.CustomerID,
AccountNumber = group.Key.AccountNumber,
Orders = group.SelectMany(x => x.Orders).ToList()
).ToList();


I would like the end result to look like this for each customer:
enter image description here



I hope this makes sense and thanks in advance for the help.










share|improve this question






















  • What should the output look like ?

    – Kunal Mukherjee
    Mar 23 at 17:21











  • It should look like the last image. Each customer should have a list of all their orders.

    – derral
    Mar 23 at 17:28











  • your code seems to be fine, now what does not work correctly?

    – Ashkan Mobayen Khiabani
    Mar 23 at 22:04











  • I don't want to have to specify each object like customerid and accountnumber in the groupby in order to have access to them in the final select

    – derral
    Mar 23 at 23:12

















0















I am working with the AdventureWorks database and I am using the following query :



 SELECT c.CustomerID, c.AccountNumber, soh.SalesOrderID, soh.SalesOrderNumber, sod.UnitPrice, sod.ProductID, p.Name
FROM Sales.SalesOrderHeader soh
inner join sales.SalesOrderDetail sod on soh.SalesOrderID = sod.SalesOrderID
inner join sales.Customer c on c.CustomerID = soh.CustomerID
inner join Production.Product p on p.ProductID = sod.ProductID


I have code already that populates the data like this just as it comes back:
enter image description here



Based on that I am wanting to merge the child list objects into a single parent to end up with a one to many structure if that makes sense.



As of right now I am hoping to use a lambda expression to do this. I have tried the following code but I don't want to have to specify --> o.CustomerID, o.AccountNumber in the group by because i would have to specify ALL the properties of my Customer class to have access to the final select as you can see in the code.



 .GroupBy(o => new o.CustomerID, o.AccountNumber ).Select(group => new Customer2

CustomerID = group.Key.CustomerID,
AccountNumber = group.Key.AccountNumber,
Orders = group.SelectMany(x => x.Orders).ToList()
).ToList();


I would like the end result to look like this for each customer:
enter image description here



I hope this makes sense and thanks in advance for the help.










share|improve this question






















  • What should the output look like ?

    – Kunal Mukherjee
    Mar 23 at 17:21











  • It should look like the last image. Each customer should have a list of all their orders.

    – derral
    Mar 23 at 17:28











  • your code seems to be fine, now what does not work correctly?

    – Ashkan Mobayen Khiabani
    Mar 23 at 22:04











  • I don't want to have to specify each object like customerid and accountnumber in the groupby in order to have access to them in the final select

    – derral
    Mar 23 at 23:12













0












0








0








I am working with the AdventureWorks database and I am using the following query :



 SELECT c.CustomerID, c.AccountNumber, soh.SalesOrderID, soh.SalesOrderNumber, sod.UnitPrice, sod.ProductID, p.Name
FROM Sales.SalesOrderHeader soh
inner join sales.SalesOrderDetail sod on soh.SalesOrderID = sod.SalesOrderID
inner join sales.Customer c on c.CustomerID = soh.CustomerID
inner join Production.Product p on p.ProductID = sod.ProductID


I have code already that populates the data like this just as it comes back:
enter image description here



Based on that I am wanting to merge the child list objects into a single parent to end up with a one to many structure if that makes sense.



As of right now I am hoping to use a lambda expression to do this. I have tried the following code but I don't want to have to specify --> o.CustomerID, o.AccountNumber in the group by because i would have to specify ALL the properties of my Customer class to have access to the final select as you can see in the code.



 .GroupBy(o => new o.CustomerID, o.AccountNumber ).Select(group => new Customer2

CustomerID = group.Key.CustomerID,
AccountNumber = group.Key.AccountNumber,
Orders = group.SelectMany(x => x.Orders).ToList()
).ToList();


I would like the end result to look like this for each customer:
enter image description here



I hope this makes sense and thanks in advance for the help.










share|improve this question














I am working with the AdventureWorks database and I am using the following query :



 SELECT c.CustomerID, c.AccountNumber, soh.SalesOrderID, soh.SalesOrderNumber, sod.UnitPrice, sod.ProductID, p.Name
FROM Sales.SalesOrderHeader soh
inner join sales.SalesOrderDetail sod on soh.SalesOrderID = sod.SalesOrderID
inner join sales.Customer c on c.CustomerID = soh.CustomerID
inner join Production.Product p on p.ProductID = sod.ProductID


I have code already that populates the data like this just as it comes back:
enter image description here



Based on that I am wanting to merge the child list objects into a single parent to end up with a one to many structure if that makes sense.



As of right now I am hoping to use a lambda expression to do this. I have tried the following code but I don't want to have to specify --> o.CustomerID, o.AccountNumber in the group by because i would have to specify ALL the properties of my Customer class to have access to the final select as you can see in the code.



 .GroupBy(o => new o.CustomerID, o.AccountNumber ).Select(group => new Customer2

CustomerID = group.Key.CustomerID,
AccountNumber = group.Key.AccountNumber,
Orders = group.SelectMany(x => x.Orders).ToList()
).ToList();


I would like the end result to look like this for each customer:
enter image description here



I hope this makes sense and thanks in advance for the help.







c# linq group-by






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 23 at 16:36









derralderral

5119




5119












  • What should the output look like ?

    – Kunal Mukherjee
    Mar 23 at 17:21











  • It should look like the last image. Each customer should have a list of all their orders.

    – derral
    Mar 23 at 17:28











  • your code seems to be fine, now what does not work correctly?

    – Ashkan Mobayen Khiabani
    Mar 23 at 22:04











  • I don't want to have to specify each object like customerid and accountnumber in the groupby in order to have access to them in the final select

    – derral
    Mar 23 at 23:12

















  • What should the output look like ?

    – Kunal Mukherjee
    Mar 23 at 17:21











  • It should look like the last image. Each customer should have a list of all their orders.

    – derral
    Mar 23 at 17:28











  • your code seems to be fine, now what does not work correctly?

    – Ashkan Mobayen Khiabani
    Mar 23 at 22:04











  • I don't want to have to specify each object like customerid and accountnumber in the groupby in order to have access to them in the final select

    – derral
    Mar 23 at 23:12
















What should the output look like ?

– Kunal Mukherjee
Mar 23 at 17:21





What should the output look like ?

– Kunal Mukherjee
Mar 23 at 17:21













It should look like the last image. Each customer should have a list of all their orders.

– derral
Mar 23 at 17:28





It should look like the last image. Each customer should have a list of all their orders.

– derral
Mar 23 at 17:28













your code seems to be fine, now what does not work correctly?

– Ashkan Mobayen Khiabani
Mar 23 at 22:04





your code seems to be fine, now what does not work correctly?

– Ashkan Mobayen Khiabani
Mar 23 at 22:04













I don't want to have to specify each object like customerid and accountnumber in the groupby in order to have access to them in the final select

– derral
Mar 23 at 23:12





I don't want to have to specify each object like customerid and accountnumber in the groupby in order to have access to them in the final select

– derral
Mar 23 at 23:12












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315967%2fgroup-child-list-into-single-parent-object-adventureworks-query-lambda-expre%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315967%2fgroup-child-list-into-single-parent-object-adventureworks-query-lambda-expre%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현