我正在尝试加入一个查询的结果以过滤第二个查询的结果。
第一次查询
// get the compound centre number and languageId key
var centreKeys = unitOfWork.CentreTranslationRepository.GetAll()
.Where(w => w.Language.cuture == searchCulture || w.language_id == 1)
.GroupBy(g => g.Centre.number)
.Select(s =>
new
{
CentreNumber = s.Key,
LanguageId = s.Max(g => g.language_id)
});
这以以下形式返回结果:
{ CentreNumber = 1589, LanguageId = 27 }
{ CentreNumber = 261, LanguageId = 1 }
{ CentreNumber = 1257, LanguageId = 1 }
{ CentreNumber = 925, LanguageId = 1 }
ETC
第二次查询
// join onto the translated table
var centres = unitOfWork.CentreTranslationRepository.GetAll()
.Join(centreKeys,
centreTranslation => new { centreTranslation.Centre.number, centreTranslation.language_id },
centreKey => new { centreKey.CentreNumber, centreKey.LanguageId },
(centreTranslation, centreKey) =>
new Centre
{
CentreNumber = centreTranslation.Centre.number,
name = centreTranslation.Centre.name
// etc
});
使用单个键执行连接没有问题,但是如上所示,我正在尝试使用匿名复合键进行连接。
这是我收到错误的时候:
Error 1 The type arguments for method 'System.Linq.Enumerable.Join<TOuter,TInner,TKey,TResult>(System.Collections.Generic.IEnumerable<TOuter>, System.Collections.Generic.IEnumerable<TInner>, System.Func<TOuter,TKey>, System.Func<TInner,TKey>, System.Func<TOuter,TInner,TResult>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. C:\Development\SVN\Projects\CentreDirectoryService\CentreDirectoryService\Services\DomainService.cs 32 65 CentreDirectoryService
我在第二个查询中做错了什么?