1

我有一个查询,它连接两个列表并创建一个新对象的列表,我想用一个新的连接来增强它,到目前为止我尝试过的一切似乎都不起作用。

名单是:

IList<Content> result
IList<Content> resultDefault

查询是:

IEnumerable<ContentItem> joined = from x in resultDefault
join y in result on new { x.ResourceKey, x.ResourceType, x.Application } equals new { y.ResourceKey, y.ResourceType, y.Application } into g
from o in g.DefaultIfEmpty(new Content()
{
  Id = 0,
  CultureCode = cultureCode,
  ResourceKey = x.ResourceKey,
  ResourceType = x.ResourceType,
  ResourceValue = String.Empty
})

where
 (
     resourcesJoin == ResourcesJoin.All ||
     (resourcesJoin == ResourcesJoin.Translated && o.ResourceValue != String.Empty) ||
     (resourcesJoin == ResourcesJoin.NotTranslated && o.ResourceValue == String.Empty)
  )
  &&
  (
     string.IsNullOrEmpty(searchString) ||
     (
         x.ResourceKey.ContainsIgnoreCase(searchString) ||
         x.ResourceValue.ContainsIgnoreCase(searchString) ||
         o.ResourceValue.ContainsIgnoreCase(searchString)
     )
  )
select new ContentItem(o, x);

到目前为止,这运作良好。

现在,我想添加第三个列表

IList<DifferentContent> resultCollection;

我已经扩展了 ContentItem 以获取 DifferentContent 的第三个参数

所以我想要类似的东西:

IEnumerable<ContentItem> joined = from x in resultDefault
    join y in result on new { x.ResourceKey, x.ResourceType, x.Application } equals new { y.ResourceKey, y.ResourceType, y.Application } into g
    from o in g.DefaultIfEmpty(new Content()
    {
      Id = 0,
      CultureCode = cultureCode,
      ResourceKey = x.ResourceKey,
      ResourceType = x.ResourceType,
      ResourceValue = String.Empty
    })
    join z in resultCollection on new { x.ResourceKey, x.ResourceType, x.Application, x.CultureCode } equals new { z.ResourceKey, z.ResourceType, z.Application, defaultCultureCode } into m
    from s in m.DefaultIfEmpty(new DifferentContent()
      {
          Id = 0,
          CultureCode = defaultCultureCode,
          ResourceKey = x.ResourceKey,
          ResourceType = x.ResourceType,
          ResourceValue = string.Empty
      })
    where
     (
         resourcesJoin == ResourcesJoin.All ||
         (resourcesJoin == ResourcesJoin.Translated && o.ResourceValue != String.Empty) ||
         (resourcesJoin == ResourcesJoin.NotTranslated && o.ResourceValue == String.Empty)
      )
      &&
      (
         string.IsNullOrEmpty(searchString) ||
         (
             x.ResourceKey.ContainsIgnoreCase(searchString) ||
             x.ResourceValue.ContainsIgnoreCase(searchString) ||
             o.ResourceValue.ContainsIgnoreCase(searchString)
         )
      )
    select new ContentItem(o, x, s);

但这是无效的。错误是:

 The type of one of the expressions in the join clause is incorrect.  Type inference failed in the call to 'GroupJoin'.

Resharper 给出了“方法的类型参数......无法推断”。不幸的是,我无法复制粘贴。

什么是正确的连接语法?

4

0 回答 0