Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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# 如何将带有join的linq表达式转换为lambda表达式?_C#_Linq_Lambda - Fatal编程技术网

C# 如何将带有join的linq表达式转换为lambda表达式?

C# 如何将带有join的linq表达式转换为lambda表达式?,c#,linq,lambda,C#,Linq,Lambda,我有以下的表达: _callPairs = (from req in _requests join resp in _responses on req.RequestId equals resp.RequestId where !string.IsNullOrEmpty(req.RequestId) sel

我有以下的表达:

_callPairs = (from req in _requests
                      join resp in _responses
                          on req.RequestId equals resp.RequestId
                          where !string.IsNullOrEmpty(req.RequestId)
                      select new CallPair(req, resp)).ToList();
我想换成lambda。我试过:

_callPairs = (from req in _requests
                      join resp in _responses
                          on req.RequestId equals resp.RequestId
                          where !string.IsNullOrEmpty(req.RequestId)
                      select new CallPair(req, resp)).ToList();
_callPairs = _requests.Where(req => (_responses.Where(res => res.RequestId == 
    req.RequestId)).Where(!string.IsNullOrEmpty(req.RequestId)).ToList();
不幸的是,这没有编译

_callPairs = (from req in _requests
                      join resp in _responses
                          on req.RequestId equals resp.RequestId
                          where !string.IsNullOrEmpty(req.RequestId)
                      select new CallPair(req, resp)).ToList();
有人能给我解释一下如何将带有连接的linq表达式转换为lambda表达式吗?

只需使用以下方法:

_callPairs = (from req in _requests
                      join resp in _responses
                          on req.RequestId equals resp.RequestId
                          where !string.IsNullOrEmpty(req.RequestId)
                      select new CallPair(req, resp)).ToList();
只需使用以下方法:

_callPairs = (from req in _requests
                      join resp in _responses
                          on req.RequestId equals resp.RequestId
                          where !string.IsNullOrEmpty(req.RequestId)
                      select new CallPair(req, resp)).ToList();

这取决于联接的类型。这里有一个内部联接(可以通过缺少
into
子句来判断),因此相应的扩展方法语法使用:

_callPairs = (from req in _requests
                      join resp in _responses
                          on req.RequestId equals resp.RequestId
                          where !string.IsNullOrEmpty(req.RequestId)
                      select new CallPair(req, resp)).ToList();

对于组联接(
join…on…into…
),您将改为使用。

这取决于联接的类型。这里有一个内部联接(可以通过缺少
into
子句来判断),因此相应的扩展方法语法使用:

_callPairs = (from req in _requests
                      join resp in _responses
                          on req.RequestId equals resp.RequestId
                          where !string.IsNullOrEmpty(req.RequestId)
                      select new CallPair(req, resp)).ToList();
对于组联接(
join…on…to…
),您将使用

_callPairs = (from req in _requests
                      join resp in _responses
                          on req.RequestId equals resp.RequestId
                          where !string.IsNullOrEmpty(req.RequestId)
                      select new CallPair(req, resp)).ToList();