Bu yapmalı. Özellikle bunun için bir test yapmamıştım. Her iki kayıtları Gerekirse
var nextProducts = from item1 in recommendations.Select((rec, idx) => new { Rec = rec, Index = idx })
join item2 in recommendations.Select((rec, idx) => new { Rec = rec, Index = idx })
on item1.Index equals item2.Index - 1
where item1.Rec.Products.Any(p => p.Code == "A")
&& item1.Rec.Products.Any(p => p.Code == "B")
select item2.Rec;
, orada olur (select ifadesi
select new { MatchingItem = item1.Rec, NextItem = item2.Rec };
olabilir Ama sonra listedeki son öğeyi olmak eşleşen öğeye hesaba bir gruplandırma yapmak zorunda kalacak Bu durumda bir sonraki öğe olmamalıdır).
var nextProducts = from item1 in recommendations.Select((rec, idx) => new { Rec = rec, Index = idx })
join item2 in recommendations.Select((rec, idx) => new { Rec = rec, Index = idx })
on item1.Index equals item2.Index - 1
into groupjoin
from i2 in groupjoin.DefaultIfEmpty()
where item1.Rec.Products.Any(p => p.Code == "A")
&& item1.Rec.Products.Any(p => p.Code == "B")
select new { MatchingItem = item1.Rec, NextItem = i2 == null ? null : i2.Rec };
Ben Test dizeleri listesiyle benzer bir şeydi yaptım kodu.
List<string> list = new List<string>() { "a", "b", "c", "a", "d", "a", "e" };
var query = from item1 in list.Select((s, idx) => new { Item = s, Index = idx })
join item2 in list.Select((s, idx) => new { Item = s, Index = idx })
on item1.Index equals item2.Index - 1
where item1.Item == "a"
select item2.Item;
Bu, b, d ve e değerini döndürür. Bir önceki cevabı çalışır Skip(1).Take(1)
kullanır
MyList.SkipWhile(item => item.Name != "someName").Skip(1).FirstOrDefault()
, ancak bir sonuç listesini verir:
+1 SQL için Ters() çalışmaz. –