how to convert this sql query to linq query? in asp.net
SELECT distinct P.Pid,P.Name,PC.categoryName,
(select count(id) from POrderdetails where id=p.Pid)as detailsCount
FROM PTable P INNER JOIN PCATEGORY PC ON PC.pcategoryId=P.pCategoryId
ORDER BY detailsCount desc
Based on your comment, I’ve updated this to include the category name. Note that the query selects them into an anonymous object — you can change that if you have an actual class with the properties by using the class constructor with property assignment instead. Note that I also gave the count a different name. As you already have a Pid, I thought pid, would be too confusing.