Basically, I have a player app that now needs to link multiple children to multiple parents. But I don't want the parents to have nested children. I feel that complicates showing in a table for example.
I have for example a table
Players
| Id | Name |
|---|---|
| 1 | Adam Goldberg |
| 2 | Barry GoldBerg |
Parents
| Id | Name |
|---|---|
| 1 | Berverly Gold Berg |
| 2 | Murry Gold Berg |
ParentsFriends Link Table
| Id | PlayerId |
|---|---|
| 1 | 1 |
| 1 | 1 |
| 2 | 2 |
As you see from the link Table Beverly gold berg should see both children, but Murry should only see the second child what my best way of outputting is this to json I tried similar to blow but didn't work.
public IEnumerable<ParentsFriend> GetAllParentsFriends(int Id)
{
var q = from parent in _db.ParentsFriends
from children in _db.Players
where parent.PlayerId == children.Id
select new ParentFriendViewModel
{
Parent1
Parent2 and so on could be relatives here as well
Children = children;
}
}
I want the json to output simply this this could be up to 4 or 5 parents? Parent1 Parent 2 Children=.......
This is an example of the json I want to output.
{
The root would show all the parents first then the children in a child node
"ParentId": 1,
"title": "Murry Gold Berg",
"description": "The best dad around",
"category": "sports",
"thumbnail": "https://dummyjson.com/image/i/products/12/thumbnail.jpg",
///All parents should be outputted here first then all the children below them?
"ParentId2": 2,
"title": "Berverly Gold Berg",
"description": "The best mom around",
"category": "sports",
"thumbnail": "https://dummyjson.com/image/i/products/12/thumbnail.jpg",
"Children": [
"Child1":
{
"Name": "Barry Gold Berg",
"AGE":18,
.....
},
"Child2":
{
"Name": "Adam Gold Berg",
"AGE":15,
.....
}
]
}