简体   繁体   English

连接多个表linq

[英]Join multiple tables linq

Pasted below is a query I am getting errors in the join. 下面粘贴的是一个查询,我在连接中遇到错误。

from c in Corporates.Where (a => a.EIN_NBR == "00-0000000")
join ep in EmployeePositions.Where (b => ((int)(b.EMPStartDate.Value.AddDays(28) - DateTime.Now.Date.AddDays(1)).Days) < 0)
        on c.ParentCorporateId equals ep.CorporateId
join ee in EmployeeEvaluations.Where(e => e.TargetGroupId != null) on ep.EmployeeId equals ee.EmployeeId
join ees in EmployeeEvaluationStatuses  on ee.EvaluationStatusId  equals ees.Id

join v in Vouchers.Where(b => b.SentDate == null)
on new {ep.EmployeeId, ee.Id} equals new {v.EmployeeId, v.EmployeeEvaluationId }

//on ep.EmployeeId equals v.EmployeeId && ee.Id equals v.EmployeeEvaluationId //在ep.EmployeeId等于v.EmployeeId && ee.Id等于v.EmployeeEvaluationId

group ep by ep.CorporateId into g
select new
{
   EmployeesMissingDocuments = g.Count()
   ,Description = "Expired"
}

I am getting the following error "Cannot execute text selection: CS1941 The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'." 我收到以下错误“无法执行文本选择:CS1941 join子句中的表达式之一的类型不正确。对'Join'的调用中类型推断失败。” at

join v in Vouchers.Where(b => b.SentDate == null)
on new {ep.EmployeeId, ee.Id} equals new {v.EmployeeId, v.EmployeeEvaluationId }

You use anonymous type to join on multiple fields. 您使用匿名类型来联接多个字段。 Anonymous type should be the same on both sides, and for that, property names (and types!) should be the same. 双方的匿名类型都应该相同,为此,属性名称(和类型!)应该相同。 In your case they are not: 在您的情况下,它们不是:

new {ep.EmployeeId, ee.Id} equals new {v.EmployeeId, v.EmployeeEvaluationId }

To fix, use the same names: 要修复,请使用相同的名称:

new {ep.EmployeeId, ee.Id} equals new {v.EmployeeId, Id = v.EmployeeEvaluationId }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM