1

2 つのリストを結合して新しいオブジェクトのリストを作成するクエリがあり、これを新しい結合で拡張したいのですが、これまでに試したすべてが機能していないようです。

リストは次のとおりです。

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);

これまでのところ、これはうまく機能しています。

次に、3 つ目のリストを追加します

IList<DifferentContent> resultCollection;

そして、ContentItem を拡張して、DifferentContent の 3 番目のパラメーターを取得したもの

だから私は次のようなものが欲しい:

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