views:

54

answers:

2

Hi there, I have two ILIst of these objects:

    class ProductionMachineType
    {
        string code { get; set; }
        IEnumerable<string> ProductionToolsLink { get; set; }
    }

    class ProductionTools
    {
        string code { get; set; }
    }

I am looking for a fast Linq method that make me able to query the IList<ProductionMachineType> that contains at least one ProductionToolsLink contained inside the ILIst<ProductionTools>.

In SQL I would wite something like this:

SELECT 
      * 
FROM 
      IList<ProductionMachineType>
WHERE 
      IList<ProductionMachineType>.ProductionToolsLink IN ILIst<ProductionTools>

Is there a way to do this?

+5  A: 

Contains method can help you:

var names = new string[] { "Alex", "Colin", "Danny", "Diego" };

var matches = from person in people
        where names.Contains(person.Firstname)
        select person;
Restuta
+2  A: 

This will do it, but I can't guarantee how efficient it is...

var output = machines.Where(machine => 
     machine.ProductionToolsLink
     .Any(link => tools.Select(tool => tool.code).Contains(link)));
ck
Ok this is the righr answer. The efficienty probles is know but I cannoto any different approach cause of our bad Domain Model.The query linq is also pretty much complicated. So I think I will use a couple of foreach to improve clarity.
Angelodev