Como usar a consulta sql de agregação condicional no Entity Framework?
Estou usando o Asp.Net MVC 5 e o Entity Framework 6.2.0 com sintaxe LINQ Extension Methods.
Eu tenho 5 tabelas de variantes, detalhes abaixo:
Tabela de produtos:
ProductID Name
12 T-Shirt
Tabela de variantes:
VariantID ProductID Name
1 12 Size
2 12 Color
3 12 Material
Tabela de Opções:
VariantOptionID VariantID VariantOptionName
1 1 Small
2 1 Medium
3 2 Red
4 2 Blue
5 3 Cotton
6 3 Lawn
Tabela de Sku:
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
Tabela VariantOptionCombination:
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
Quero mostrar esses registros de tabelas na página da web como.
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
Eu estou usando esta consulta para alcançar a saída desejada. Como posso traduzir esta consulta no 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;