问题
I've two Entities In VS 2015 Model
Halaqat_Test (Parent) has Primary Key (MsqID)
Halaqat_Test2 (Child) has FOREIGN Key (MsqID)
there is no link or Any Association between those two entities. yesterday i do link each entity to another. by using this Code
var result = db.Halaqati_Test.GroupJoin
(db.Halaqati_Test2,
c => c.msq_id,
s => s.MsqID,
(c, s) => new { Mosque = c, Rings = s });
return result;
but the problem is that the child Table columns Halaqati_Test2 (Not Included inside the parent Property In The Json)
it looks Like :
[
{
"Mosque": {
"msq_id": 3,
"MsqName": "Center 1",
"RowNum": 1
},
"Rings": [
{
"RingID": 613,
"RingName": "aaaa",
"MsqID": 3,
"RowNum": 231
},
{
"RingID": 614,
"RingName": "bbb",
"MsqID": 3,
"RowNum": 232
},
{
"RingID": 615,
"RingName": "ccc",
"MsqID": 3,
"RowNum": 233
}
]
}
]
but is should and the expected json is :
[
{
"Mosque": {
"msq_id": 3,
"MsqName": "Center 1",
"RowNum": 1,
"Rings": [
{
"RingID": 613,
"RingName": "aaaa",
"MsqID": 3,
"RowNum": 231
},
{
"RingID": 614,
"RingName": "bbb",
"MsqID": 3,
"RowNum": 232
},
{
"RingID": 615,
"RingName": "ccc",
"MsqID": 3,
"RowNum": 233
}
]
}
}
]
Update
I want to like a derived entity from the Halaqati_Test2 as (parent) to the view_stdwithrings (Child)
Halaqati_Test2.RingID = view_stdwithrings.rg_id
how i can make that level under of rings, so will be rings have more thatn one student what should i do exactly to make sure that the child comes inside the parent node.
回答1:
It is this line that selects - thus creates resulting json structure. Because you select "Mosque" and "Rings" on the same level, you get a json structure that reflects it:
(c, s) => new { Mosque = c, Rings = s });
Try changing it to:
(c, s) => new { Mosque = new { msq_id = c.msq_id, MsqName = c.MsqName, RowNum = c.RowNum, Rings = s }});
(Disclaimer: i dont have a coding environment here, so i cant test this code)
来源:https://stackoverflow.com/questions/33735336/how-to-include-the-derived-table-columns-inside-the-json-nested