Querygen now works in all cases. There is a bug with importing entity into the inner template scope (the original code is availanle via version TemplateVersion, the workaround uses string mixins)