Isn't it the carrier who's flight code/number you're flying? If you're flying UA flight #xxx, but really operated as LH flight #yyy, it's the UA flight number that gets posted to your DM account. So, I always thought you'd get the mileage credit based on what the DM stipulates as eligible miles for UA in this example.
That's true on AA and other
oneworld carriers, but not on US or any *A partner.