0

I have this code:

Strutture = from Ricettivito s in Strutture
            where s.ServiziAttivi.Cast<string>().Intersect(IDSServizi).Count() == IDSServizi.Count()
            select s;

I need to:

  1. Cast ServiziAttivi (which is a list of MyService) into a list of string (which must contains MyService.UniqueID)
  2. Than, check if this list contains each elements of IDSServizi (which is a list of string).

But seems I cannot doint that conversion?

markzzz
  • 47,390
  • 120
  • 299
  • 507

2 Answers2

4

First cast to .Cast<Ricettivita.MyService>() then select a string property.

    where s.ServiziAttivi
             .Cast<Ricettivita.MyService>()
             .Select(x=>x.UniqueID).Intersect(IDSServizi).Count()
I4V
  • 34,891
  • 6
  • 67
  • 79
  • If OP did a .ToList() would they need a cast, first? Assuming OPs custom collection class inherits from Enumerable in some way. – J. Steen Apr 17 '13 at 14:30
1

I think you should use Select instead of Cast:

Strutture = from Ricettivito s in Strutture
            where s.ServiziAttivi.Select(x => (string)x.UniqueID).Intersect(IDSServizi).Count() == IDSServizi.Count()
            select s;
MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263