Cook onions in salted boiling water for 5 minutes. Drain well and stir in cheese. Mix in almost all the egg and season with salt and pepper to taste.
Pour mixture into pastry-lined pan, and place second sheet of pastry on top of filling. Seal edges and cut vents in top. Brush pastry with remaining egg and place in preheated oven. Bake 30 minutes. Can be served hot or cold.