Lorentz, this is the default behavior of the Entity Framework. You have to explicitly define your custom behavior based on what the system should do.
First, you can access the State of your entities within the context using hte following example:
EntityState state = db.Entry<Station>(station).State;
You can print the states and then see what EF is doing.
Now, when you first receive the instance of Template, its state on the context it will be Detached.
After you add it to the context, the state will change to Added. This will apply for Template(s), Station(s) and TimePeriod(s).
Even if you set the Id (Primary Key) correctly, EF will discard the ids, create new Ids and add new lines to the tables, which is what is happening with your program. That is what I managed to reproduce in my code.
You have to define the EntityState for each entity so the EF will know that it should not persist new items. Below are the possible values at EF 6.1:
// This is probably what you are looking for
db.Entry<Station>(station).State = EntityState.Unchanged;
// This one maybe, if you are receiving updated values for the State
db.Entry<Station>(station).State = EntityState.Modified;
// Others that may apply for other scenarios
db.Entry<Station>(station).State = EntityState.Detached;
db.Entry<Station>(station).State = EntityState.Added;
db.Entry<Station>(station).State = EntityState.Deleted;
Since Template have multiple itens for Station and TimePeriod you will have to iterate over them and set each one as "Unchanged" I assume, or "Modified".
Let me know if it works.