I am using Asp.Net MVC 5 and Entity Framework 6.2.0 with LINQ Extension Methods syntax.
I have 5 tables of variants, details below:
Product Table:
ProductID Name 12 T-Shirt
Variant Table:
VariantID ProductID Name 1 12 Size 2 12 Color 3 12 Material
VariantOption Table:
VariantOptionID VariantID VariantOptionName 1 1 Small 2 1 Medium 3 2 Red 4 2 Blue 5 3 Cotton 6 3 Lawn
Sku Table:
SkuID ProductID SKU Price Barcode 1 12 Th-Sm-Red-Cot 120.00 345423 2 12 Th-Sm-Red-Lon 130.00 345454 3 12 Th-Sm-Blue-Cot 140.00 345451 4 12 Th-Sm-Blue-Lon 150.00 345431 5 12 Th-Md-Red-Cot 160.00 345472 6 12 Th-Md-Red-Lon 170.00 345479 7 12 Th-Md-Blue-Cot 180.00 654353 8 12 Th-Md-Blue-Lon 190.00 254353
VariantOptionCombination Table:
VariantOptionID SkuID 1 1 3 1 5 1 1 2 3 2 6 2 1 3 4 3 5 3 1 4 4 4 6 4
I want to show these tables records on web page as.
Size Color Material Price Sku Small Red Cotton 120.00 345423 Small Red Lawn 130.00 345454 Small Blue Cotton 140.00 345451 Small Blue Lawn 150.00 345431 Medium Red Cotton 160.00 345472 Medium Red Lawn 170.00 345479 Medium Blue Cotton 180.00 654353 Medium Blue Lawn 190.00 254353
I am using this query to achieve the desire output. How can i translate this query in Entity Framework linq?
select max(case when v.Name = 'Size' then vo.Name end) as Size, max(case when v.Name = 'Color' then vo.Name end) as Color, max(case when v.Name = 'Material' then vo.Name end) as Material, s.price from ProductSKU s join ProductVariantOptionCombination voc on s.SkuID = voc.SkuId join ProductVariantOption vo on vo.VariantOptionId = voc.VariantOptionId join ProductVariant v on v.VariantId = vo.VariantId group by s.Price;