We identify a class of term structure models possessing a generalized affine-structure that significantly extends the class studied by Duffie, Pan, and Singleton (2000) and Chacko and Das (2002). This class of models, which includes both infinite-state-variable (i.e., HJM-type) and infinite-factor (random field) models, possesses analytic solutions for the characteristic function, which in turn provides closed-form solutions for many types of fixed income derivatives. In addition, the generalized affine framework provides analytic solutions to the optimal portfolio choice problem. In a random field setting, the optimal portfolio decision is unique, in turn providing a justification for 'preferred habitat' theories.