, . , , ? , , , - , table.References, , Reference (.. refer.PrimaryTable == "myTable"), , Table (Table) Reference (refer).
, Table Reference PrimaryTable == "myTable", tables Table. ?
, , , , Table References Reference PrimaryTable == "myTable". , tables.Add(table) break, . ( , Reference PrimaryTable, , . , , .)
( , ) . , Reference ( ToList IEnumerable<Reference>).
, , , , , :
var tables = dbServer.Tables
.Where(table => !table.IsSet)
.Where(
table => table.References.Any(refer => refer.PrimaryTable == "myTable")
).ToList();
ORIGINAL RESPONSE
I'm going to expand Lee's answer. Analyze it line by line.
foreach (Table table in dbServer.Tables)
{
if (!table.IsSet)
{
foreach (Reference refer in table.References)
{
if (refer.PrimaryTable == "myTable")
{
tables.Add(table);
}
}
}
}
OK So we have:
- Enumeration - just - where we start
- Checking conditions - we will need
Where - Listing over another collection -
SelectMany - Status Check -
WhereAgain - Adding - most likely
ToList(depends on what type of collection you want)
Here is the result:
var tables = dbServer.Tables
.Where(table => !table.IsSet)
.SelectMany(table => table.References)
.Where(refer => refer.PrimaryTable == "myTable")
.ToList();
Make sense?