I am working on an older database application that uses .Net Web Forms, and the first step to a long process of revamping this application has lead me to a problem with Entity Framework 6. Actually, it's a problem with me not knowing how to do something in Entity Framework, more specifically, with a Linq query. I don't want to go too far into detail, so I'm simplifying a few of the Entity Diagrams here, then I'll ask for help in cracking the nut that I have been unable to crack.
Simplified Entities
Desired result |
I can do this with SQL easy enough and concatenate the Comments into one column using a sub-query like so:
SQL Query with a sub-query for Comments |
There are probably cleaner ways to get this done in SQL in more recent versions, but this is something I've been using since around 2007. I am considering using a Stored Procedure in my database, but I don't want to have these decisions made based on the fact that I don't know how to do something with one technology vs. the other.
Here is my attempt so far. I've created a C# class to act as a View Model
And here is part of the IssueFactory class and the function that will return the List
So that's it. Googling has gotten me nowhere with this for a few days. I thought I was going to be slick, and tried to call another function that I had created that built the bulleted list, but of course, linq queries can't call C# code like this, unfortunately.
So what's the piece of the puzzle that I have been missing? Anyone?
Thanks, in advance!
Why not just model comments as part of Issues? If you look at the EF Core Docs, the getting started sample shows how to iterate "blogs" with "posts." It's the same structure as "issues" and "comments". What are you trying to do that is not addressed by this sample? https://docs.microsoft.com/ef/core/get-started/
ReplyDeleteI had a lot of input on Reddit, and finally came up with a solution. I was putting this all in a Crystal Report...so I was trying to "flatten" everything out before passing it on to the report. I ended up using Linq to get a List, and then did a foreach on that List, and a StringBuilder to build the ultimate Comment, which is just a concat of all of the CommentText.
Delete