我有 LINQ 查询:
var qty = db.WebOEOrdD.Sum(d => d.QTY);
var unitPrice = db.IcPricP.Select(p => decimal.Round(p.UNITPRICE, 2));
var query = from item in db.OrderFormDump
join icp in db.IcPricP on item.ITEMNO.Replace("-", "") equals icp.ITEMNO
join itemInfo in db.WebItemInfo on item.ITEMNO equals itemInfo.ITEMNO
join weboeordh in db.WebOEOrdH on username equals weboeordh.USER
join weboeordd in db.WebOEOrdD on new { itemno = item.ITEMNO.Replace("-", ""), orduniq = weboeordh.ORDUNIQ } equals new { itemno = weboeordd.ITEMNO, orduniq = weboeordd.ORDUNIQ }
join weboeordsubmit in db.WebOEOrdSubmit on weboeordd.ORDUNIQ equals weboeordsubmit.ORDUNIQ where weboeordsubmit.ORDUNIQ != weboeordd.ORDUNIQ
join webloginaccess in db.WebLoginAccess on username equals webloginaccess.USER
join arcus in db.Arcus on webloginaccess.CUSTID equals arcus.IDCUST
where (item.ALLOWINBC == "Yes" && item.ALLOWINAB == "Yes")
&& icp.PRICELIST == arcus.PRICLIST
&& icp.CURRENCY == "CDN" && icp.DPRICETYPE == 1
&& (item.BASEDESCRIPTION.Contains(searchword) || item.DESCRIPTION.Contains(searchword) || item.CATEGORY.Contains(searchword) || item.FOODACCSPEC.Contains(searchword) || item.ITEMBRAND.Contains(searchword) || item.ITEMGROUP.Contains(searchword) || item.ITEMNO.Contains(searchword) || item.ITEMSUBTYPE.Contains(searchword) || item.ITEMTYPE.Contains(searchword) || itemInfo.INFO.Contains(searchword) || item.UPC.Contains(searchword) || item.UPC.Substring(2, 10).Contains(searchword))
orderby item.BASEDESCRIPTION
group item by new { item.ITEMNO, item.BASEDESCRIPTION, itemInfo.INFO, item.UPC, unitPrice, item.CASEQTY, qty } into items
select new { items.Key.ITEMNO, items.Key.BASEDESCRIPTION, items.Key.INFO, items.Key.UPC, unitPrice, items.Key.CASEQTY, qty };
我收到此错误:
用于调用' GroupBy'的键选择器类型方法在底层商店提供商中无法比较。
我正在以这种方式编写LINQ查询,因为我试图从此SQL查询转换它:
SELECT orderformdump.itemno,basedescription,info,upc,CAST(UNITPRICE AS DECIMAL(18,2)),caseqty, sum(qty) AS userquantity
FROM [DataWarehouse].[dbo].[ORDERFORMDUMP]
LEFT JOIN PPPLTD.dbo.ICPRICP ON replace([DataWarehouse].[dbo].[ORDERFORMDUMP].[ITEMNO],'-','') = ICPRICP.ITEMNO
LEFT JOIN PPPLTD.dbo.WEBITEMINFO ON ORDERFORMDUMP.ITEMNO = WEBITEMINFO.ITEMNO
LEFT JOIN pppltd.dbo.weboeordh ON [user] = 'brian'
LEFT JOIN pppltd.dbo.weboeordd ON pppltd.dbo.WEBOEORDD.ITEMNO = REPLACE(datawarehouse.dbo.ORDERFORMDUMP.ITEMNO,'-','') and weboeordd.ORDUNIQ = weboeordh.orduniq
Left JOIN pppltd.dbo.weboeordsubmit ON weboeordsubmit.orduniq = weboeordd.ORDUNIQ and weboeordd.ORDUNIQ != weboeordsubmit.orduniq
LEFT JOIN PPPLTD.dbo.WEBLOGINACCESS ON WEBLOGINACCESS.[USER] = 'brian'
LEFT JOIN PPPLTD.dbo.ARCUS ON ARCUS.IDCUST = WEBLOGINACCESS.CUSTID
where (allowinbc = 'Yes' or allowinab = 'Yes')
AND [PRICELIST] = ARCUS.PRICLIST
and [CURRENCY] = 'CDN' and DPRICETYPE = 1
and (itemgroup like '%' + @search + '%' or itemtype like '%' + @search + '%' or itembrand like '%' + @search + '%'
or subcat like '%' + @search + '%' or orderformdump.description like '%' + @search + '%' or basedescription like '%'+ @search + '%'
or orderformdump.ITEMNO like '%'+@search+'%' or UPC like '%'+@search+'%' or (select top 1 1 from pppltd.dbo.ICITEMO where OPTFIELD like 'UPC%' and VALUE like '%'+@search+'%'
and ITEMNO = DataWarehouse.dbo.ORDERFORMDUMP.itemno) is not null)
group by ORDERFORMDUMP.ITEMNO,BASEDESCRIPTION,info,UPC,CAST(UNITPRICE AS DECIMAL(18,2)),caseqty
order by basedescription
并且我不太确定如何转换如此长的查询。
更新
由于我的unitPrice
和qty
变量,我收到此错误。删除后,我不再有错误。