0

いくつかのプロパティを含む Content というクラスがあります

プロパティの 1 つは CultureCode です。

リスト A にはすべての「en」コンテンツ クラスが含まれます リスト B にはすべての「en-GB」コンテンツ クラスが含まれます

それらをマージして、最終リストに「en」コンテンツのみを取得しますが、en の代わりに最終リストにその項目を含めるという条件で en-GB に一致する場合はいつでも取得します。

したがって、次の場合:

リストA

en - 1
en - 2
en - 3
en - 4
en - 5

リストB

en-GB - 2
en-GB - 4
en-GB - 6

それから

混合リスト

en - 1
en-GB - 2
en - 3
en-GB - 4
en - 5

私はこのようなことを試しました:

IEnumerable<Content> mixed = from x in listA
join y in listB on new {x.Property1, x.Property2, x.Property3} equals
    new {y.Property1, y.Property2, y.Property3} into g
from o in g.DefaultIfEmpty(new Content()
{
    Id = x.Id,
    CultureCode = x.CultureCode,
    Property1 = x.Property1,...
})
where
(
    ...
)
select new Content()
{
    Id = o.Id,
    CultureCode = o.CultureCode,
    Property1 = o.Property1,
    Property2 = o.Property2,
    Property3 = o.Property3,
};

その複数のバリエーションがありますが、結果はまったく正確ではありません。

何か案は?

4

1 に答える 1

1

これに沿った何かがそれを行います:

var result = (from a in listA
              join b in listB on a.Property1 equals b.Property1 into g
              from j in g.DefaultIfEmpty()
              select new Content() { 
                   // Favour listA's culture code
                   CultureCode = j == null ? a.CultureCode : j.CultureCode, 
                   Property1 = a.Property1 
              });

デモ用の実例: http://rextester.com/AAWQ92029

于 2014-01-22T11:35:51.633 に答える