0

Ok, so I have two elements:

class Full
{
    public string FullId {get; set;}
    public List<string> Tapes {get; set;}
}

and

class OptSet
{
    public string SetId {get; set;}
    public list<string> Tapes2 {get; set;}
}

I need to select a Full which list of Tapes contains all elements from OptSet list of Tapes2.

I need to do it in Linq. I've tried

Full currFull = inputFull.Where(f => 
    f.Tapes.Contains(OptSet.Tapes2.ToString())).FirstOrDefault();

but this results in null.

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
Piotr Truszkowski
  • 208
  • 1
  • 2
  • 12

1 Answers1

0

Does this work?

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Full full = new Full()
            {
                FullId = "A",
                Tapes = new List<string>() { "1", "2", "4" }
            };



            List<OptSet> optSet = new List<OptSet>() {
                new OptSet() { SetId = "x", Tapes2 = new List<string>() {"1", "2", "3"}},
                new OptSet() { SetId = "y", Tapes2 = new List<string>() {"1", "2", "4"}},
                new OptSet() { SetId = "z", Tapes2 = new List<string>() {"1", "2", "3", "4"}}
            };


            List<OptSet> results = optSet.Where(x => full.Tapes.Where(y => !x.Tapes2.Contains(y)).Count() == 0).ToList();

        }
    }
    public class Full
    {
        public string FullId { get; set; }
        public List<string> Tapes { get; set; }
    }


    public class OptSet
    {
        public string SetId { get; set; }
        public List<string> Tapes2 { get; set; }
    }

}

​
jdweng
  • 33,250
  • 2
  • 15
  • 20