I assume this is similar to the question you asked over on stackoverflow?
You can add elements dynamically by searching the identityProvider collection using StringCollectionContains. If it's not there, link it.
Does the IDP pass the email address? If it doesn't you have to have something to search B2C for to find the local account?
You can search B2C for any attribute e.g. loyalty number:
HTH