【发布时间】:2011-12-12 16:09:38
【问题描述】:
所以我想从我的左连接 sql 中进行 linq 查询(请参阅下面的内容)。我只是不知道如何正确定位连接上的“.TournamentId = 1”条件。目前在我的数据库上运行它时,我得到了我想要的结果。这是 Type 表中带有空字段的几行。
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)或其他东西?
【问题讨论】:
标签: linq entity-framework linq-to-entities