But i want to write a code by which i am able to use the pivot code in linq to get the output as
ProductName 2016 2017 2018
cedar oil NULL 16 34
computer NULL 8 1
grain NULL 21 NULL
Keyboard 2 3 NULL
marie NULL 26 NULL
Pine Oil NULL 4 5
harabhara kebabNULL 5 1
For this i have written the sql query
- select *
- from(
- select pd.ProductName,year(dsm.CreatedDate)as [Year],sum(dsm.ProductQuantity)as ProductQuantity
- from dbo.DatewiseStockDetailMaster dsm
- left join dbo.StockMaster sm on
- dsm.stock_Id=sm.stock_Id
- left join dbo.ProductDetails pd
- on sm.ProductId=pd.ProductId
- where sm.CompanyId=17 and dsm.IsProductDeducted=1
- group by year(dsm.CreatedDate),pd.ProductName
- )as SourceTable
- pivot
- (
- sum(ProductQuantity)
- for [Year]
- in([2016],[2017],[2018])
- )
- as pivotTable
Can anyone help me convert this SQL to Linq