// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Linq; namespace E { public class Doc { public int Dokumnr {get; set;} } public class Row { public int Dokumnr {get; set;} public int Product {get; set;} } public class Program { public static void Main(string[] args) { List alldocs = new List(); alldocs.Add(new Doc { Dokumnr=1 } ); alldocs.Add(new Doc { Dokumnr=2 } ); alldocs.Add(new Doc { Dokumnr=3 } ); List allrows = new List(); allrows.Add(new Row { Dokumnr=1, Product=123 } ); allrows.Add(new Row { Dokumnr=2, Product=122 } ); allrows.Add(new Row { Dokumnr=3, Product=123 } ); var q = from d in alldocs where (from r in allrows where r.Product==123 select r.Dokumnr).Contains(d.Dokumnr) select d; foreach(Doc d in q) { Console.WriteLine(d.Dokumnr); } } } }