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()