Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将foreach和if转换为linq查询_C#_Linq_Linq Query Syntax - Fatal编程技术网

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;
}