我正在使用连接从多个表中获取数据,并且下面附有一个表图像,这会导致问题。该表跟踪测试的状态,我想要具有进程 id 11 的测试,但是作为其跟踪表的多行 reutrning,这导致在我看来重复一个记录三次,我试图在 bookingdid 上应用 groupby 并获取最大 trackid这是表的唯一标识,但我无法做到我的 linq 查询也在下面。任何帮助。
这是我的 linq 查询:
using (var db = new bc_limsEntities())
{
var result = (from d in db.dc_tpatient_bookingd
join m in db.dc_tpatient_bookingm on d.bookingid equals m.bookingid into a
from m in a.DefaultIfEmpty()
join p in db.dc_tpatient on m.prid equals p.prid into b
from p in b.DefaultIfEmpty()
join t in db.dc_tp_test on d.testid equals t.TestId into c
from t in c.DefaultIfEmpty()
//join mt in db.dc_tp_tmethod on t.TestId equals mt.testid into j
//from mt in j.DefaultIfEmpty()
// join gm in db.dc_tp_groupm on t.GroupId equals gm.GroupId into e
//from gm in e.DefaultIfEmpty()
join pn in db.dc_tpanel on m.panelid equals pn.panelid into f
from pn in f.DefaultIfEmpty()
join og in db.dc_tp_organization on m.clientid equals og.OrgId into g
from og in g.DefaultIfEmpty()
join w in db.dc_tp_ward on m.wardid equals w.wardid into h
from w in h.DefaultIfEmpty()
join tb in db.dc_tp_branch on m.BranchID equals tb.BranchID into i
from tb in i.DefaultIfEmpty()
join bd in db.dc_tp_refdoctors on m.doctorid equals bd.doctorid into k
from bd in k.DefaultIfEmpty()
join dt in db.dc_tstatustrack on d.bookingdid equals dt.bookingdid into l
from dt in l.DefaultIfEmpty()
where d.ProcessID == 5
&& t.SubdepartmentId == subDepartmentID
&& fromDate <= m.enteredon && m.enteredon <= DateTime.Now
&& d.status != "H"
&& DateTime.Now > d.deliverytime
&& dt.processid == 11
select new { d, p, m, t, bd, pn, dt }).Distinct().ToList();
我做了这样的事情但对我不起作用:
group new { d, p, m, t, bd, pn, dt } by new { dt.bookingdid } into mno
任何帮助将不胜感激