C# 将foreach和if转换为linq查询
但是它告诉我下面的错误@C# 将foreach和if转换为linq查询,c#,linq,linq-query-syntax,C#,Linq,Linq Query Syntax,但是它告诉我下面的错误@l.Key SourceSchemaInfos.ForEach(Database =>Database.SchemaInfos.ForEach(items => items.SchemaInfos.ForEach(tables => tables.SchemaInfos.Where(tables.Key == SelectedTables.ForEach(l => l.Key)).ForEach(m => m.IsSelected = t
l.Key
SourceSchemaInfos.ForEach(Database =>Database.SchemaInfos.ForEach(items => items.SchemaInfos.ForEach(tables => tables.SchemaInfos.Where(tables.Key == SelectedTables.ForEach(l => l.Key)).ForEach(m => m.IsSelected = true))));
`请尝试以下代码。我认为这是正确的
LINQ
转换您的查询
CS0201 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
请尝试以下代码。我认为这是正确的
LINQ
转换您的查询
CS0201 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
foreach (var _tableschema in
(from db in SourceSchemaInfos from table in db.SchemaInfos from tablelist in table.SchemaInfos
select tablelist)
.SelectMany(tablelist => SelectedTables.Where(t => tablelist.Key == t.Key)
.SelectMany(t => tablelist.SchemaInfos)
))
{
_tableschema.IsSelected = true;
}
var schemaInfos = from db in SourceSchemaInfos
from table in db.SchemaInfos
from tableList in table.SchemaInfos
from selectedTable in SelectedTables
where tableList.Key == selectedTable.Key
select tableList.SchemaInfos;
foreach(var tableSchema in schemaInfos)
{
tableSchema.IsSelected = true;
}