Converting a LINQ query to methods

1

The following query in LINQ (with query) below is used to list all providers that have an account (relationship 1 to 1):

from f in fornecedores
join c in contas on f.ID equals c.FornecedorID
select f

How can I achieve the same result using LINQ methods with .Select() ... ?

    
asked by anonymous 06.09.2018 / 20:10

1 answer

1

To use Join, it is much better to use the syntax instead of the methods, since the Join () method has {4.5} parameters, which makes reading more difficult.

Still, answering your question, your query would look like:

fornecedores.Join(contas, f => f.ID, c => c.FornecedorID, (f, c) => f);

Parameters:

1st: Collection you will Join

2nd: Key to the first collection

3rd: Key to the second collection

4º: Function that returns the result item, it is almost the same as using the Select (), however it receives two parameters, the first is the item from the first collection (suppliers), the second is the item from the second collection ( accounts).

    
10.09.2018 / 15:21