{
"data": [
{
"product_id": "1",
"name": "Product 1",
"image": "/Conten/product_image/1.jpg",
"attrs": [
{
"id": "1",
"weight": "500 Grams",
"price": "1.300",
"old_price": "1.300",
"qty": "5"
},
{
"id": "3",
"weight": "1KG",
"price": "1.300",
"old_price": "1.300",
"qty": "5"
}
]
},
{
"product_id": "2",
"name": "Product 2",
"image": "/Conten/product_image/2.jpg",
"attrs": [
{
"id": "5",
"weight": "250 Grams",
"price": "0.700",
"old_price": "0.700",
"qty": "2"
},
{
"id": "6",
"weight": "2 KG",
"price": "1.300",
"old_price": "1.300",
"qty": "1"
}
]
}
]
}
У меня есть две таблицы
- tblProducts с product_id, name, main_image
- tblProduct_attr с идентификатором,product_id,attr_value,price,old_price,qty
Это мой код соединения Linq двух таблиц.
var _products = (from p in db.tblProducts
join a in db.tblProduct_attr on p.product_id equals a.product_id
select new
{
product_id = p.product_id,
name = p.name,
image = p.main_image,
id = a.id,
weight = a.attr_value,
price = a.price,
old_price = a.old_price,
qty = a.qty
}).ToList();
Подробнее здесь: https://stackoverflow.com/questions/791 ... in-c-sharp