Lambda expression with department name with branch name












0















<Employee>
<Data>
<Details type = "Personal">
<Detail Name ="John" Associate Job="Job">
<Department Name="Law" >
<Branch>New York</Branch>
<Branch>Florida</Branch>
</Department>
<Department Name="Lecture" >
<Branch>London</Branch>
<Branch>Brit</Branch>
</Department>
</Detail>
</Details>
</Data>
</Employee>


Output




Law -- New York,
Florida

Lecture -- London,
Brit


Lambda expression for above XML format :---



var employee = (from r in document.Descendants("Detail").Where(r => (string)r.Attribute("Name") == "John")select new { key = r.Element("Department").Attribute("Name").Value, value = (from type in (r.Element("Department").Elements("Branch")) select type.Value).ToArray() })
.ToDictionary(t => t.key, t => t.value);



Only one records is coming




Law -- New York,
Florida


Missing : -




Lecture -- London,
Brit









share|improve this question




















  • 1





    Pure code-writing requests are off-topic on Stack Overflow — we expect questions here to relate to specific programming problems — but we will happily help you write it yourself! Tell us what you've tried, and where you are stuck. This will also help us answer your question better.

    – Micha Wiedenmann
    Nov 5 '18 at 12:17
















0















<Employee>
<Data>
<Details type = "Personal">
<Detail Name ="John" Associate Job="Job">
<Department Name="Law" >
<Branch>New York</Branch>
<Branch>Florida</Branch>
</Department>
<Department Name="Lecture" >
<Branch>London</Branch>
<Branch>Brit</Branch>
</Department>
</Detail>
</Details>
</Data>
</Employee>


Output




Law -- New York,
Florida

Lecture -- London,
Brit


Lambda expression for above XML format :---



var employee = (from r in document.Descendants("Detail").Where(r => (string)r.Attribute("Name") == "John")select new { key = r.Element("Department").Attribute("Name").Value, value = (from type in (r.Element("Department").Elements("Branch")) select type.Value).ToArray() })
.ToDictionary(t => t.key, t => t.value);



Only one records is coming




Law -- New York,
Florida


Missing : -




Lecture -- London,
Brit









share|improve this question




















  • 1





    Pure code-writing requests are off-topic on Stack Overflow — we expect questions here to relate to specific programming problems — but we will happily help you write it yourself! Tell us what you've tried, and where you are stuck. This will also help us answer your question better.

    – Micha Wiedenmann
    Nov 5 '18 at 12:17














0












0








0








<Employee>
<Data>
<Details type = "Personal">
<Detail Name ="John" Associate Job="Job">
<Department Name="Law" >
<Branch>New York</Branch>
<Branch>Florida</Branch>
</Department>
<Department Name="Lecture" >
<Branch>London</Branch>
<Branch>Brit</Branch>
</Department>
</Detail>
</Details>
</Data>
</Employee>


Output




Law -- New York,
Florida

Lecture -- London,
Brit


Lambda expression for above XML format :---



var employee = (from r in document.Descendants("Detail").Where(r => (string)r.Attribute("Name") == "John")select new { key = r.Element("Department").Attribute("Name").Value, value = (from type in (r.Element("Department").Elements("Branch")) select type.Value).ToArray() })
.ToDictionary(t => t.key, t => t.value);



Only one records is coming




Law -- New York,
Florida


Missing : -




Lecture -- London,
Brit









share|improve this question
















<Employee>
<Data>
<Details type = "Personal">
<Detail Name ="John" Associate Job="Job">
<Department Name="Law" >
<Branch>New York</Branch>
<Branch>Florida</Branch>
</Department>
<Department Name="Lecture" >
<Branch>London</Branch>
<Branch>Brit</Branch>
</Department>
</Detail>
</Details>
</Data>
</Employee>


Output




Law -- New York,
Florida

Lecture -- London,
Brit


Lambda expression for above XML format :---



var employee = (from r in document.Descendants("Detail").Where(r => (string)r.Attribute("Name") == "John")select new { key = r.Element("Department").Attribute("Name").Value, value = (from type in (r.Element("Department").Elements("Branch")) select type.Value).ToArray() })
.ToDictionary(t => t.key, t => t.value);



Only one records is coming




Law -- New York,
Florida


Missing : -




Lecture -- London,
Brit






c# .net linq c#-4.0 lambda






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 4:26







suraj

















asked Nov 5 '18 at 12:08









surajsuraj

62




62








  • 1





    Pure code-writing requests are off-topic on Stack Overflow — we expect questions here to relate to specific programming problems — but we will happily help you write it yourself! Tell us what you've tried, and where you are stuck. This will also help us answer your question better.

    – Micha Wiedenmann
    Nov 5 '18 at 12:17














  • 1





    Pure code-writing requests are off-topic on Stack Overflow — we expect questions here to relate to specific programming problems — but we will happily help you write it yourself! Tell us what you've tried, and where you are stuck. This will also help us answer your question better.

    – Micha Wiedenmann
    Nov 5 '18 at 12:17








1




1





Pure code-writing requests are off-topic on Stack Overflow — we expect questions here to relate to specific programming problems — but we will happily help you write it yourself! Tell us what you've tried, and where you are stuck. This will also help us answer your question better.

– Micha Wiedenmann
Nov 5 '18 at 12:17





Pure code-writing requests are off-topic on Stack Overflow — we expect questions here to relate to specific programming problems — but we will happily help you write it yourself! Tell us what you've tried, and where you are stuck. This will also help us answer your question better.

– Micha Wiedenmann
Nov 5 '18 at 12:17












1 Answer
1






active

oldest

votes


















0














You can select all the Department elements first:



var employee = (from r in document.Descendants("Detail").Where(r => (string)r.Attribute("Name") == "John").SelectMany(x => x.Elements("Department"))
select new { key = r.Attribute("Name").Value,
value = (from type in r.Elements("Branch") select type.Value).ToArray() })
.ToDictionary(t => t.key, t => t.value);





share|improve this answer
























  • Thank xiaosu, it is working now

    – suraj
    Nov 29 '18 at 4:41











  • @suraj Please mark this as answer if it is accepted by you.

    – Xiaosu
    Nov 29 '18 at 4:59











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%2f53154128%2flambda-expression-with-department-name-with-branch-name%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You can select all the Department elements first:



var employee = (from r in document.Descendants("Detail").Where(r => (string)r.Attribute("Name") == "John").SelectMany(x => x.Elements("Department"))
select new { key = r.Attribute("Name").Value,
value = (from type in r.Elements("Branch") select type.Value).ToArray() })
.ToDictionary(t => t.key, t => t.value);





share|improve this answer
























  • Thank xiaosu, it is working now

    – suraj
    Nov 29 '18 at 4:41











  • @suraj Please mark this as answer if it is accepted by you.

    – Xiaosu
    Nov 29 '18 at 4:59
















0














You can select all the Department elements first:



var employee = (from r in document.Descendants("Detail").Where(r => (string)r.Attribute("Name") == "John").SelectMany(x => x.Elements("Department"))
select new { key = r.Attribute("Name").Value,
value = (from type in r.Elements("Branch") select type.Value).ToArray() })
.ToDictionary(t => t.key, t => t.value);





share|improve this answer
























  • Thank xiaosu, it is working now

    – suraj
    Nov 29 '18 at 4:41











  • @suraj Please mark this as answer if it is accepted by you.

    – Xiaosu
    Nov 29 '18 at 4:59














0












0








0







You can select all the Department elements first:



var employee = (from r in document.Descendants("Detail").Where(r => (string)r.Attribute("Name") == "John").SelectMany(x => x.Elements("Department"))
select new { key = r.Attribute("Name").Value,
value = (from type in r.Elements("Branch") select type.Value).ToArray() })
.ToDictionary(t => t.key, t => t.value);





share|improve this answer













You can select all the Department elements first:



var employee = (from r in document.Descendants("Detail").Where(r => (string)r.Attribute("Name") == "John").SelectMany(x => x.Elements("Department"))
select new { key = r.Attribute("Name").Value,
value = (from type in r.Elements("Branch") select type.Value).ToArray() })
.ToDictionary(t => t.key, t => t.value);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 5:13









XiaosuXiaosu

3701619




3701619













  • Thank xiaosu, it is working now

    – suraj
    Nov 29 '18 at 4:41











  • @suraj Please mark this as answer if it is accepted by you.

    – Xiaosu
    Nov 29 '18 at 4:59



















  • Thank xiaosu, it is working now

    – suraj
    Nov 29 '18 at 4:41











  • @suraj Please mark this as answer if it is accepted by you.

    – Xiaosu
    Nov 29 '18 at 4:59

















Thank xiaosu, it is working now

– suraj
Nov 29 '18 at 4:41





Thank xiaosu, it is working now

– suraj
Nov 29 '18 at 4:41













@suraj Please mark this as answer if it is accepted by you.

– Xiaosu
Nov 29 '18 at 4:59





@suraj Please mark this as answer if it is accepted by you.

– Xiaosu
Nov 29 '18 at 4:59


















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%2f53154128%2flambda-expression-with-department-name-with-branch-name%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

Paul Cézanne

UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

Angular material date-picker (MatDatepicker) auto completes the date on focus out