I have two lists Requestsand Responsesthat inherit from an abstract class AbstractLineModel. Both responses and requests contain an identifier (or not) with a name RequestId.
A CallPaircontains the matching pair Requestand a Responseand has the following constructor:
public AbstractLineModel _request { get; set; }
public AbstractLineModel _response { get; set; }
public CallPair(AbstractLineModel request, AbstractLineModel response)
{
_request = request;
_response = response;
}
I want to do List CallPairswhere Requestwith the same identifier as, it Responsemaps to CallPair. How to match the list Requestsand Responses?
What I tried:
public void MatchCallPairs()
{
var requestWithMatches = _requests
.Where(req => _responses.All(res => res.RequestId == req.RequestId)).ToList();
foreach (var req in requestWithMatches)
{
var resp = _responses.Where(res => res.RequestId == req.RequestId).FirstOrDefault();
_callPairs.Add(new CallPair(req, resp));
}
}
but this returns an empty list.
In particular, it var requestWithMatches = _requests
.Where(req => _responses.All(res => res.RequestId == req.RequestId)).ToList();returns an empty list of requestsWithMatches.
Can someone help me with this algorithm?