1
所以我想从我的左连接SQL中做一个linq查询(参考下面)。我只是不知道如何正确定位连接上的“.TournamentId = 1”条件。目前,当我在我的数据库上运行这个时,我得到了我想要的结果。这是来自类型表的具有空字段的几行。linq 2左连接
select typ.Id, stat.PromoterId, temp.PromoterId
from ReportTypes type
left join ReportTemplateStatus status on status.PromoterId = type.TypeId and status.TournamentId = 1
left join ReportTemplates temp on temp.ClientId = status.PromoterId and temp.TournamentId = 1
Promoter
- promoterId
- promoterName
Tournament
- tournamentId
- tournamentName
ReportType
- TypeId
ReportTemplateStatus
- promoterId (this is the key)
- tournamentId
- typeId
ReportTemplates
- promoterId
- tournamentId
这是目前我有:
var report = from type in context.ReportTypes
join status in context.ReportTemplateStatus on type.TypeId equals status.TypeId
join temp in context.ReportTemplates on status.promoterId equals temp.promoterId into iReports
from reports in iReports.Where (rep => rep.promoterId == _promoterId && rep.tournamentId == _tournamentId).DefaultIfEmpty()
select new { my fields});
,但它给了我一个空。
linq应该如何工作的任何想法?也许分成“itables”(iReports)或其他东西?