0

I have an SQL query using the unpivot function. I want convert this query into a LINQ query

select MvNumber,DocumentName , Expire_Date  
From VehicleDetails 

Unpivot
(
 Expire_Date for DocumentName in ([TaxUpTo] ,[InsuranceUpTo],[PUCUpTo],[FitnessUpTo])
)as p 

I want to use this query into asp .net MVC c#, in a controller, in the form of view,

currently, i use this code

public ActionResult Index()
    {
        var list = _vehicleDetailsService.GetAll().OrderBy(x => x.MvNumber);
        return View(list);
    }
  • there is no conversion for Unpivot in linq to sql. but you can somehow simulate your unpivot , check here https://stackoverflow.com/questions/10188774/is-unpivot-not-pivot-functionality-available-in-linq-to-sql-how – Amir Jelo Nov 30 '19 at 09:15
  • Usually it's better to leave such special queries in the database as a view and query the view by LINQ. The database is better equipped to do this than any LINQ-ish solution will be. – Gert Arnold Nov 30 '19 at 12:01

0 Answers0