How to convert this foreach loop into Linq code?
- by a-galkin
I am new one with Linq and I would like to modify my old c# code to use Linq.
The idea of this code to select all tables where it's not set and reference’s field PrimaryTable equal "myTable"
foreach (Table table in dbServer.Tables)
            {
                if (!table.IsSet)
                {
                    foreach (Reference refer in table.References)
                    {
                        if (refer.PrimaryTable == "myTable")
                        {
                            tables.Add(table);
                        }
                    }
                }
            }
After digging in internet I have got this code
var q = from table in dbServer.Tables
                    let refers = from refer in table.References
                                 where refer.PrimaryTable == "myTable"
                                 select refer.ForeignTable
                    where refers.Contains(table.Name)
                    select table;
But it does not work at all and I need your help to make it works.
Thanks in advance.