You'd need to start with some custom comparers to customize the way that the join performs matching:
public class MaterialXMLComparer : IEqualityComparer<MaterialXML>
{
private IEqualityComparer<AlternateUnitXML> _alternateComparer;
public MaterialXMLComparer(IEqualityComparer<AlternateUnitXML> alternateComparer)
{
_alternateComparer = alternateComparer;
}
public bool Equals(MaterialXML x, MaterialXML y)
{
bool firstLevelEqual = (x.Reference == y.Reference) &&
(x.MeasurementUnitCode == y.MeasurementUnitCode);
if (firstLevelEqual)
{
if (x.AlternateUnits.SequenceEqual(y.AlternateUnits, _alternateComparer))
{
return true;
}
}
return false;
}
public int GetHashCode(MaterialXML obj)
{
return obj.Reference.GetHashCode();
}
}
public class AlternateUnitXMLComparer : IEqualityComparer<AlternateUnitXML>
{
public bool Equals(AlternateUnitXML x, AlternateUnitXML y)
{
return (x.Code == y.Code) &&
(x.PrimaryQuantity == y.PrimaryQuantity) &&
(x.SecondaryQuantity == y.SecondaryQuantity);
}
public int GetHashCode(AlternateUnitXML obj)
{
return obj.Code.GetHashCode();
}
}
Then, you can use the Join method directly to add in the custom comparers:
var joinedList = matListA.Join(matListB,
x => x,
y => y,
(x, y) => x,
new MaterialXMLComparer(new AlternateUnitXMLComparer()));
joinedList now contains just the entry from matListA that matched some entry from matListB.