Lambda expression with department name with branch name
<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
add a comment |
<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
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
add a comment |
<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
<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
c# .net linq c#-4.0 lambda
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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);
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
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
add a comment |
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);
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
add a comment |
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);
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);
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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