我已经通过SQL完成了这个查询,并希望转换为LINQ
SELECT
ENT_DESC,
CAT_DESC,
PART_NUM,
PART_DESC,
GROUP_CONCAT(PART_OPTIONS.CODE, CHAR(13)) AS CODE,
PART_OPTIONS.PROMPT AS PROMPT,
PART_OPTIONS.DESCRIPTION AS DESCRIPTION,
PART_OPTIONS.PRICE AS PRICE,
ATTRIBUTE_DATA.NOTE,
ATTRIBUTE_DATA.DESCRIPTION AS ATTR_DESC
FROM ITEM_DATA
LEFT JOIN PART_OPTIONS ON ITEM_DATA.ID = PART_OPTIONS.PART_ID
LEFT JOIN ATTRIBUTE_DATA ON ITEM_DATA.ID = ATTRIBUTE_DATA.PART_ID
GROUP BY PART_OPTIONS.PART_ID
我知道如何在没有GROUP_CONCAT的情况下执行此操作,
from c in ITEM_DATA
join a in ATTRIBUTE_DATA on c.ID equals a.PART_ID into at
from a in at.DefaultIfEmpty()
join p in PART_OPTIONS on c.ID equals p.PART_ID into pa
from p in pa.DefaultIfEmpty()
select new {
ENT_DESC = c.ENT_DESC,
CAT_DESC = c.CAT_DESC,
PART_NUM = c.PART_NUM,
PART_DESC = c.PART_DESC,
CODE = p.CODE,
PROMPT = p.PROMPT,
DESCRIPTION = p.DESCRIPTION,
PRICE = p.PRICE,
NOTE = a.NOTE,
ATTR_DESC = a.DESCRIPTION,
}
我也分别完成了GROUP_CONCAT
from c in ITEM_DATA
join a in ATTRIBUTE_DATA on c.ID equals a.PART_ID into at
from a in at.DefaultIfEmpty()
join p in PART_OPTIONS on c.ID equals p.PART_ID into pa
from p in pa.DefaultIfEmpty()
group p by p.PART_ID into ps
select new {
CODE = ps.Select(g=>g.CODE),
}
但之后“c”和“a”消失了,我不知道如何访问ITEM_DATA和ATTRIBUTE_DATA表。