c# - How to get "remainder" of query (all non-matched pairs) in LINQ and collect it in a list -


i matching requests responses based on requestid follows:

    public void matchcallpairsbyrequestid()     {         // finds request have matching response based on requestid , create callpair        _callpairs = _requests.where(req => !string.isnullorempty(req.requestid))                   .join(_responses,                          req => req.requestid,                         resp => resp.requestid,                         (req, resp) => new callpair(req, resp)).tolist();     } 

or in linq expression:

 _callpairs = (from req in _requests                   join resp in _responses                       on req.requestid equals resp.requestid                       !string.isnullorempty(req.requestid)                   select new callpair(req, resp)).tolist(); 

now want collect requests , responses not matched function in separate list called nonmatchedrequests , nonmatchedresponses. how use query collect remainder in separate list?

i'm not sure if there way in 1 call or perhaps merge producing list of pairs, can run couple of follow methods determine unmatched items:

var unmatchedrequests = _requests.except(_callpairs.select(cp => cp.request));  var unmatchedresponses = _responses.except(_callpairs.select(cp => cp.response)); 

the documentation enumerable.join talks of being able use groupjoin perform outer join, detailed here, return unmatched requests, though think miss unmatched responses.

i await bated breath answer demonstrating linq wizardry more efficiently 1 call.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -