我正在尝试将我的 SQL 查询转换为 linq 到实体。
这是我的 SQL 查询
SELECT DISTINCT
voidSEVT.RESTYPE, voidSEVT.SESID, voidWO.WONUM, voidSEVT.T_START,
voidSEVT.USER3
FROM
VOIDWO AS voidWO
JOIN
voidSEVT ON voidWO.SEQNUM = voidSEVT.SEQNUM
LEFT OUTER JOIN
PROJECTS AS prj ON voidWO.PRJ_ID = prj.PRJ_ID
LEFT OUTER JOIN
RESTYPE ON voidSEVT.RTYPE = RESTYPE.CODE
JOIN
RSRCE as resource on voidSEVT.RESID = resource.RESID
WHERE
(voidSEVT.USERFLAG4 != 1)
AND (LRTRIM(RTRIM(voidSEVT.USER3)) <> '')
我的 sql 查询输出是
RESTYPE SESID WONUM T_START USER3
0 7245100 1477491 1352239200 0030\r\n0060\r\n
4 7245098 1477491 1352239200 0030\r\n0060\r\n
4 7245099 1477491 1352239200 0030\r\n0060\r\n
5 7245097 1477491 1352239200 0030\r\n0060\r\n
5 7245101 1477491 1352239200 0030\r\n0060\r\n
这是我对实体的 linq
public List<ReversalEntity> ReversalList()
{
var db = new SchedwinEntities();
var query =
( from voidWO in db.VOIDWOes
join voidSEVT in db.VOIDSEVTs on voidWO.SEQNUM equals voidSEVT.SEQNUM into voidSEVT_join
from voidSEVT in voidSEVT_join.DefaultIfEmpty()
join prj in db.PROJECTS on voidWO.PRJ_ID equals prj.PRJ_ID into prj_join
from prj in prj_join.DefaultIfEmpty()
from voidSevtJoin in voidSEVT_join.DefaultIfEmpty()
join restype in db.RESTYPEs on voidSevtJoin.RTYPE equals restype.CODE into RESTYPEs_join
from restypes in RESTYPEs_join.DefaultIfEmpty()
join resource in db.RSRCEs on voidSEVT.RESID equals resource.RESID into RSRCS_join
where
(voidSEVT.USERFLAG4.value != 1) &&
(voidSEVT.USER3.Trim().Length > 0)
select new
{
resourceType = voidSEVT.RESTYPE,
voidSEVT.SESID,
wonum = voidWO.WONUM,
start = voidSEVT.T_START,
usage = voidSEVT.USER3,
SAPCCr = ((voidSEVT.RESTYPE == 5 || voidSEVT.RESTYPE == 0)?prj.USER3:prj.USER9),
activity = restypes.USER2,
sendercc = restypes.USER1,
resdesc = RSRCS_join.FirstOrDefault().DES,
Type=voidSEVT.RESTYPE,
jobdesc = voidWO.JOBDESC,
}).Distinct();
我的 sql 查询返回 20 条记录,如下所示
RESTYPE SESID WONUM T_START USER3
0 7245100 1477491 1352239200 0030\r\n0060\r\n
0 7245100 1477491 1352239200 0030\r\n0060\r\n
0 7245100 1477491 1352239200 0030\r\n0060\r\n
0 7245100 1477491 1352239200 0030\r\n0060\r\n
4 7245098 1477491 1352239200 0030\r\n0060\r\n
4 7245098 1477491 1352239200 0030\r\n0060\r\n
4 7245098 1477491 1352239200 0030\r\n0060\r\n
4 7245098 1477491 1352239200 0030\r\n0060\r\n
etc...
基本上每条记录每条记录都有 3 个重复项,因此我的输出总数为 20。看起来有些连接在这里不合适但不确定。
有人告诉我这里缺少什么吗?