You can add template directive at the beginning of the template file in order to add assemblies and namespaces.
[%@template language="CSharp" providerOptions="CompilerVersion=v3.5" %]
[%@ Reference name="C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" %]
[%@ namespace name="System.Linq" %]