2 回答
TA贡献1784条经验 获得超2个赞
我不确定这会有多大帮助,因为它是你的SQL的翻译,你的LINQ似乎与你的SQL无关,但我有:
var ans = from p in db.JDE_Processes
join uuu in db.JDE_Users on p.FinishedBy equals uuu.UserId into uuuj
from uuu in uuuj.DefaultIfEmpty()
join h in db.JDE_Handlings on p.ProcessId equals h.ProcessId into hj
from h in hj
group new { p, h } by new { p.ProcessId, p.Description, p.StartedOn, p.StartedBy, p.FinishedOn, p.FinishedBy, p.PlannedFinish, p.PlannedStart } into phg
select new {
phg.Key.ProcessId,
phg.Key.Description,
phg.Key.StartedOn,
phg.Key.StartedBy,
phg.Key.FinishedOn,
phg.Key.FinishedBy,
phg.Key.PlannedFinish,
phg.Key.PlannedStart,
HandlingStatus = phg.Where(ph => ph.h.IsCompleted == null).Count()
};
TA贡献2036条经验 获得超8个赞
很抱歉回答我自己的问题,但我已经找到了2的答案)。我只是不知道如何为一个属性创建别名,当我有2个具有相同名称的属性(例如“姓氏”)时。请在下面找到包含别名以及NetMage解决的条件计数器部分的代码:
var items = (from p in db.JDE_Processes
join uuu in db.JDE_Users on p.FinishedBy equals uuu.UserId into finished
from fin in finished.DefaultIfEmpty()
join uu in db.JDE_Users on p.StartedBy equals uu.UserId into started
from star in started.DefaultIfEmpty()
join h in db.JDE_Handlings on p.ProcessId equals h.ProcessId into hans
from ha in hans.DefaultIfEmpty()
where p.TenantId == tenants.FirstOrDefault().TenantId && p.CreatedOn >= dFrom && p.CreatedOn <= dTo
group new { p, fin, star, ha }
by new {
p.ProcessId,
p.Description,
p.StartedOn,
p.StartedBy,
p.FinishedOn,
p.FinishedBy,
p.PlannedFinish,
p.PlannedStart,
fin.Name,
fin.Surname,
StarterName = star.Name, // <-- Creating alias
StarterSurname = star.Surname // <-- Creating alias
} into grp
orderby grp.Key.ProcessId descending
select new Process
{
ProcessId = grp.Key.ProcessId,
Description = grp.Key.Description,
StartedOn = grp.Key.StartedOn,
StartedBy = grp.Key.StartedBy,
StartedByName = grp.Key.StarterName + " " + grp.Key.StarterSurname,
FinishedOn = grp.Key.FinishedOn,
FinishedBy = grp.Key.FinishedBy,
FinishedByName = grp.Key.Name + " " + grp.Key.Surname,
PlannedStart = grp.Key.PlannedStart,
PlannedFinish = grp.Key.PlannedFinish,
HandlingStatus = grp.Where(ph=>ph.ha.IsCompleted == null && ph.ha.HandlingId >0).Count().ToString()
});
- 2 回答
- 0 关注
- 98 浏览
添加回答
举报