A quantum mechanical investigation on the effects of the solvent and the structure on nonlinear optical activity of a class of merocyanine compounds has been conducted. The interplay of the two effects on the first hyperpolarizability, computed at density functional theory and second-order Møller-Plesset level, has been analyzed in combination with ground state properties and geometries and excited state energies and dipoles. A critical analysis of the simplified two-level model has also been presented.