I have two tables in my database Stores and Products with the following fields
TBL_Store
StoreID (Primary Key)
StoreName
TBL_PRODUCT
ProductID (Primary Key)
StoreID (Foreign Key)
ProductName
INT_TYPE
I am using the following query to create JSON array
var data = context.tbl_product.Where(x => x.INT_TYPE == 1).ToList();
var json = JsonConvert.SerializeObject(data, Formatting.Indented,
new JsonSerializerSettings() {
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
It gives me all relational tables data with Repeated Entries.
I want my json to be something like this
[{
"Store": {
"storeid": "1",
"storename": "Nike",
"Products": [{
"ProdID": "1",
"prodName": "NikeShoes1"
}, {
"ProdID": "2",
"prodName": "NikeShoes2"
}, {
"ProdID": "3",
"prodName": "NikeShoes3"
}]
},
"Store": {
"storeid": "2",
"storename": "Biba",
"Products": [{
"ProdID": "1",
"prodName": "Biba1"
}, {
"ProdID": "2",
"prodName": "Biba2"
}, {
"ProdID": "3",
"prodName": "Biba3"
}]
}
}]