如何编写linq查询以从两个表中选择数据?

时间:2019-02-16 15:54:06

标签: c# linq

你好,这是我的linq查询,

 var RoutineRemarks = (from i in _context.TableA.Include(a => a.pm_routine_report_type)
                              from j in _context.TableB.Include(a => a.PM_Evt_Cat).Include(b => b.department).Include(c => c.employees).Include(d => d.provncs)

                              orderby i.seen_by_executive_on descending
                              orderby j.English_seen_by_executive_on descending



                              // Here i face the problem, i want to select i+j
                              select i+j).ToList();

最后,它只允许我选择i或j,但是我想同时选择两者,我该怎么做?

1 个答案:

答案 0 :(得分:0)

以这种方式尝试

select new {I=i, J=j}).ToList(); 

我也同意@GertArnold。您的主要查询很可能需要联接,但是在不知道ERD的情况下很难说出您需要做什么