Correct Way to Retrieve Header Records With Filtered Detail Records [closed]

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I wrote this in LinqPad. It works. The whole point was to retrieve header records, and only include some detail records. I'm looking for possible improvements to this, specifically around the anonymous type part. The only way I was able to get this to work as to use an anonymous type, then create the ToEntitySet() extension method to convert the detail rows. I just feel like I'm making this harder than it is. But maybe not? Any comments are welcome.
void Main()
var query =
from header in AccountHeader
join detail in AccountDetail
on header.AccountHeaderId equals detail.AccountHeaderId
into groupedDetails
where groupedDetails.Any(x => x.Status == "status2")
select new
Account = header,
AccountDetail = groupedDetails.Where(x => x.Status == "status2")
;
foreach (var item in query)
var account = item.Account;
account.AccountDetail = item.AccountDetail.ToEntitySet();
account.Dump();
public static class Extensions
public static EntitySet<T> ToEntitySet<T> (this IEnumerable<T> source) where T : class
var entitySet = new EntitySet<T> ();
entitySet.AddRange (source);
return entitySet;
c# linq entity-framework
closed as off-topic by t3chb0t, hjpotter92, Raystafarian, Mast, Imus Apr 9 at 11:42
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â t3chb0t, hjpotter92, Raystafarian, Imus
 |Â
show 3 more comments
up vote
2
down vote
favorite
I wrote this in LinqPad. It works. The whole point was to retrieve header records, and only include some detail records. I'm looking for possible improvements to this, specifically around the anonymous type part. The only way I was able to get this to work as to use an anonymous type, then create the ToEntitySet() extension method to convert the detail rows. I just feel like I'm making this harder than it is. But maybe not? Any comments are welcome.
void Main()
var query =
from header in AccountHeader
join detail in AccountDetail
on header.AccountHeaderId equals detail.AccountHeaderId
into groupedDetails
where groupedDetails.Any(x => x.Status == "status2")
select new
Account = header,
AccountDetail = groupedDetails.Where(x => x.Status == "status2")
;
foreach (var item in query)
var account = item.Account;
account.AccountDetail = item.AccountDetail.ToEntitySet();
account.Dump();
public static class Extensions
public static EntitySet<T> ToEntitySet<T> (this IEnumerable<T> source) where T : class
var entitySet = new EntitySet<T> ();
entitySet.AddRange (source);
return entitySet;
c# linq entity-framework
closed as off-topic by t3chb0t, hjpotter92, Raystafarian, Mast, Imus Apr 9 at 11:42
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â t3chb0t, hjpotter92, Raystafarian, Imus
2
You need to unfoo your code and post the real one. Currently this is off-topic.
â t3chb0t
Apr 7 at 20:08
1
Why do I need to unfoo my code? How does that make a difference?
â Bob Horn
Apr 7 at 20:17
1
Well, I'm stuck then, because my company doesn't want me to post our types. I'm really struggling to understand how it really matters. This is real code, with just a couple of types renamed. Does that really alter the overall understanding of what I've posted?
â Bob Horn
Apr 7 at 20:35
1
Maybe try to find different names that still make sense and don't look like pseudocode... It's really hard to follow foos. We don't know your code and seeting only garbage isn't helping to understand it.
â t3chb0t
Apr 7 at 20:40
3
That was sarcasm.
â Jim
Apr 7 at 22:05
 |Â
show 3 more comments
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I wrote this in LinqPad. It works. The whole point was to retrieve header records, and only include some detail records. I'm looking for possible improvements to this, specifically around the anonymous type part. The only way I was able to get this to work as to use an anonymous type, then create the ToEntitySet() extension method to convert the detail rows. I just feel like I'm making this harder than it is. But maybe not? Any comments are welcome.
void Main()
var query =
from header in AccountHeader
join detail in AccountDetail
on header.AccountHeaderId equals detail.AccountHeaderId
into groupedDetails
where groupedDetails.Any(x => x.Status == "status2")
select new
Account = header,
AccountDetail = groupedDetails.Where(x => x.Status == "status2")
;
foreach (var item in query)
var account = item.Account;
account.AccountDetail = item.AccountDetail.ToEntitySet();
account.Dump();
public static class Extensions
public static EntitySet<T> ToEntitySet<T> (this IEnumerable<T> source) where T : class
var entitySet = new EntitySet<T> ();
entitySet.AddRange (source);
return entitySet;
c# linq entity-framework
I wrote this in LinqPad. It works. The whole point was to retrieve header records, and only include some detail records. I'm looking for possible improvements to this, specifically around the anonymous type part. The only way I was able to get this to work as to use an anonymous type, then create the ToEntitySet() extension method to convert the detail rows. I just feel like I'm making this harder than it is. But maybe not? Any comments are welcome.
void Main()
var query =
from header in AccountHeader
join detail in AccountDetail
on header.AccountHeaderId equals detail.AccountHeaderId
into groupedDetails
where groupedDetails.Any(x => x.Status == "status2")
select new
Account = header,
AccountDetail = groupedDetails.Where(x => x.Status == "status2")
;
foreach (var item in query)
var account = item.Account;
account.AccountDetail = item.AccountDetail.ToEntitySet();
account.Dump();
public static class Extensions
public static EntitySet<T> ToEntitySet<T> (this IEnumerable<T> source) where T : class
var entitySet = new EntitySet<T> ();
entitySet.AddRange (source);
return entitySet;
c# linq entity-framework
edited Apr 7 at 20:42
asked Apr 7 at 19:36
Bob Horn
13617
13617
closed as off-topic by t3chb0t, hjpotter92, Raystafarian, Mast, Imus Apr 9 at 11:42
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â t3chb0t, hjpotter92, Raystafarian, Imus
closed as off-topic by t3chb0t, hjpotter92, Raystafarian, Mast, Imus Apr 9 at 11:42
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â t3chb0t, hjpotter92, Raystafarian, Imus
2
You need to unfoo your code and post the real one. Currently this is off-topic.
â t3chb0t
Apr 7 at 20:08
1
Why do I need to unfoo my code? How does that make a difference?
â Bob Horn
Apr 7 at 20:17
1
Well, I'm stuck then, because my company doesn't want me to post our types. I'm really struggling to understand how it really matters. This is real code, with just a couple of types renamed. Does that really alter the overall understanding of what I've posted?
â Bob Horn
Apr 7 at 20:35
1
Maybe try to find different names that still make sense and don't look like pseudocode... It's really hard to follow foos. We don't know your code and seeting only garbage isn't helping to understand it.
â t3chb0t
Apr 7 at 20:40
3
That was sarcasm.
â Jim
Apr 7 at 22:05
 |Â
show 3 more comments
2
You need to unfoo your code and post the real one. Currently this is off-topic.
â t3chb0t
Apr 7 at 20:08
1
Why do I need to unfoo my code? How does that make a difference?
â Bob Horn
Apr 7 at 20:17
1
Well, I'm stuck then, because my company doesn't want me to post our types. I'm really struggling to understand how it really matters. This is real code, with just a couple of types renamed. Does that really alter the overall understanding of what I've posted?
â Bob Horn
Apr 7 at 20:35
1
Maybe try to find different names that still make sense and don't look like pseudocode... It's really hard to follow foos. We don't know your code and seeting only garbage isn't helping to understand it.
â t3chb0t
Apr 7 at 20:40
3
That was sarcasm.
â Jim
Apr 7 at 22:05
2
2
You need to unfoo your code and post the real one. Currently this is off-topic.
â t3chb0t
Apr 7 at 20:08
You need to unfoo your code and post the real one. Currently this is off-topic.
â t3chb0t
Apr 7 at 20:08
1
1
Why do I need to unfoo my code? How does that make a difference?
â Bob Horn
Apr 7 at 20:17
Why do I need to unfoo my code? How does that make a difference?
â Bob Horn
Apr 7 at 20:17
1
1
Well, I'm stuck then, because my company doesn't want me to post our types. I'm really struggling to understand how it really matters. This is real code, with just a couple of types renamed. Does that really alter the overall understanding of what I've posted?
â Bob Horn
Apr 7 at 20:35
Well, I'm stuck then, because my company doesn't want me to post our types. I'm really struggling to understand how it really matters. This is real code, with just a couple of types renamed. Does that really alter the overall understanding of what I've posted?
â Bob Horn
Apr 7 at 20:35
1
1
Maybe try to find different names that still make sense and don't look like pseudocode... It's really hard to follow foos. We don't know your code and seeting only garbage isn't helping to understand it.
â t3chb0t
Apr 7 at 20:40
Maybe try to find different names that still make sense and don't look like pseudocode... It's really hard to follow foos. We don't know your code and seeting only garbage isn't helping to understand it.
â t3chb0t
Apr 7 at 20:40
3
3
That was sarcasm.
â Jim
Apr 7 at 22:05
That was sarcasm.
â Jim
Apr 7 at 22:05
 |Â
show 3 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
2
You need to unfoo your code and post the real one. Currently this is off-topic.
â t3chb0t
Apr 7 at 20:08
1
Why do I need to unfoo my code? How does that make a difference?
â Bob Horn
Apr 7 at 20:17
1
Well, I'm stuck then, because my company doesn't want me to post our types. I'm really struggling to understand how it really matters. This is real code, with just a couple of types renamed. Does that really alter the overall understanding of what I've posted?
â Bob Horn
Apr 7 at 20:35
1
Maybe try to find different names that still make sense and don't look like pseudocode... It's really hard to follow foos. We don't know your code and seeting only garbage isn't helping to understand it.
â t3chb0t
Apr 7 at 20:40
3
That was sarcasm.
â Jim
Apr 7 at 22:05