给出以下数据库表层次结构:
Region
------
RegionId
RegionName
Country
-------
CountryId
RegionId
CountryName
Destination
-----------
DestinationId
CountryId
DestinationName
Venue
-----
VenueId
DestinationId
VenueName
我有以下实体框架查询:
var result = from region in context.Region.Include("Country.Destination.Venue")
select region
将返回所有表中的所有行(外部联接)
是否可以引入where子句,以便只包含场地不为null的行(或使用内部联接)?
由于
答案 0 :(得分:1)
试试这个。它应该返回您要查找的结果:只有具有相应位置的区域。
var result = from region in context.Region.Include(Country.Destination.Venue)
let v = (from ctry in region.Country
join dest in context.Destination
on ctry.CountryId
equals dest.CountryId
into destGroup
from dests in destGroup
join ven in context.Venue
on dests.DestinationId
equals ven.DestinationId
into venGroup
select ctry).Any()
where v == true
select region;