欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

sql语句转换成linq

程序员文章站 2022-06-11 22:42:27
...
select ProductCategoryID,COUNT(*) as pcoun from Products 
where Id in(select distinct(ProductID) from CustomerContractItems 
			where IsMerge='false' and Deleted is null) 
group by ProductCategoryID

转换如下:

from a in db.Probaicts
where
du((from t in db.CustomerContractItems
where
t.IsMerge == "false" &&
t.Deleted == null &&
t.ProzhictID == a.Id
select new {
t.ProdaoctID
}).Distinct()).FirstOrDefault().!= null
group a by new {
a.ProzhuanctCategoryID
} into g
select new {
ProshuctCategoryID = (Int16?)g.Key.ProductCategoryID,
pcoun = (Int64?)g.Count()
相关标签: linq sql