I am connecting 2 in memory collections
var items = from el in elements join def in Cached.Elements() on el.Value equals def.Name into temp1 from res in temp1.DefaultIfEmpty() select new { el.NodeType, res.DefKey, res.DefType, res.BaseKey, el.Value };
However, ideally, if one of the elements cannot be found, I would like to create an exception, something similar to
throw new System.Exception(el.Value + " cannot be found in cache!");
I looked at System.Interactive, which offers a Catch extension method, but I'm not sure how to reference the current "el" in this context. So, for example, I was interested in something like
var items = ( from el in elements join def in Cached.Elements() on el.Value equals def.Name into temp1 from res in temp1.DefaultIfEmpty() select new { el.NodeType, res.DefKey, res.DefType, res.BaseKey, el.Value }) .ThrowIfEmpty();
but istm that this would entail passing the entire set to an extension method, rather than raising an exception when a missing value is encountered.
Alternatively, I can replace DefaultIfEmpty with ThrowIfEmpty
var items = ( from el in elements join def in Cached.Elements() on el.Value equals def.Name into temp1 from res in temp1.ThrowIfEmpty() select new { el.NodeType, res.DefKey, res.DefType, res.BaseKey, el.Value });
Is there a βrightβ / best way to do this?