如何将JSON的内部派生表列(嵌套) [英] How To Include the Derived Table Columns inside the Json (Nested)
问题描述
我有两个实体
在 VS 2015年型号
Halaqat_Test
(家长)有主键
(将对msqid
) Halaqat_Test2
(儿童)具有外键
(将对msqid
)
Halaqat_Test
(Parent) has Primary Key
(MsqID
)
Halaqat_Test2
(Child) has FOREIGN Key
(MsqID
)
有这两个实体之间没有联系或任何关联。
昨天,我做的每一个实体连接起来。通过使用这种code
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;
但问题是,孩子表
列 Halaqati_Test2
(不是父属性在<$里面包括C $ C>的Json )
它看起来像:
[
{
"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
}
]
}
]
但应该和预期的JSON是:
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
}
]
}
}
]
更新
我要像从Halaqati_Test2为(父)到view_stdwithrings(儿童)
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.
推荐答案
在这条线的选择 - 从而造成产生的JSON结构。因为你选择清真寺,并在同一水平上指环王,你会得到一个JSON结构,反映了它:
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 }});
(声明:我没有在这里有一个编码环境,所以我不能测试这个code)
(Disclaimer: i dont have a coding environment here, so i cant test this code)
这篇关于如何将JSON的内部派生表列(嵌套)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!