【发布时间】:2019-06-24 22:39:34
【问题描述】:
我想知道是否可以使用来自Entity Framework 连接查询的结果。
请忽略连接查询是否有意义。我只是想解释我的问题,而不是提出正确的查询。为了清楚起见,我将其简化了很多:
var firstJoinQuery = (from company in this.TimesheetsContext.companies
join country in this.TimesheetsContext.Countries
on company.CountryId equals country.Id
where (country == 'USA')
select new { CountryId = country.Id }).Distinct();
var secondJoinQuery = (from country in this.TimesheetsContext.Countries
join firstJoinQuery
on country.CountryId equals firstJoinQuery.CountryId
select new { Country = country }).Distinct();
我发誓我以前做过,但是我无法得到一个联接的结果,以便在第二个或第三个中使用。
我想这样做的原因是为了让事情更容易阅读,因为在使用 EF 和复杂查询时它并不总是很明显。
我目前的解决方法转向实际的存储过程,因为它肯定更容易阅读,但如果可能,我想先在 EF 中试一试。
谢谢。
【问题讨论】:
标签: c# entity-framework join