If the first part is the key of D, and it is, then D Major is the key. You can use the D major scale until the cows come home and it'll sound great... even though you won't really be playing D Major (huh?)
Because, the TONAL CENTER, not the key, is Emin. That's the chord that sounds like home base. It's the sound that the song keeps coming back to. Emin, in the key of D, is the ii chord, so E Dorian would be the actual sound that we will hear.
You could play D Major/Ionian, E Dorian, F# Phrgian, G Lydian, A Mixolydian, B Aeolian/Natural Minor, or even C# Locrian, and they'll all work, because they are all relative and have the same set of notes.
But at the end of the day, they'll all sound like E Dorian because that's what the chords say - and the chords always win.
The 2nd part, being in the key of G means G Major scale - full stop. You can play A Dorian, B Phrygian, C Lydian, D Mixolydian, E Aeolian, or F# Locrian because they are all the same notes... but the chords, to me, say G Major so that's just where I'd keep my brain.
Playing A Dorian instead of G Major is literally nothing but a brain exercise - your fingers play the same notes. So just pick a mode, mentally, that makes sense, and play. If you don't love the sound, put your brain on a different mode of the same key and see if you like that better.
Once you put your brain into a certain mode, it's going to navigate to certain notes as being more important... that's all. It's totally mental, the notes won't change between relative modes.