linq返回一个不同的列表

这是返回模板的唯一列表的最佳方法吗?当我添加联接时,它将返回所有重复记录。我收到不支持的错误

“ ExceptionMessage”:“成员'OrderTemplateTool.Data.Template.TemplateId'不支持SQL转换。”,

    public IQueryable<TemplatesJoinAgent> GetTemplatesPublishAgent()
    {
        var source = from t in UnitOfWork.GetRepository<Template>().Get()
               join r in UnitOfWork.GetRepository<Regimen>().Get() on t.Id equals r.TemplateId
               join rp in UnitOfWork.GetRepository<RegimenPart>().Get() on r.Id equals rp.RegimenId
               join re in UnitOfWork.GetRepository<RegimenEntry>().Get() on rp.Id equals re.RegimenPartId
               join a in UnitOfWork.GetRepository<Agent>().Get() on re.AgentVersionKey equals a.VersionKey
               where t.IsCurrentVersion && t.Status == (short)TemplateMode.Published && a.IsCurrentVersion
               select new TemplatesJoinAgent
               {
                   Template = t,
                   Agent = a

               };

        source = source.GroupBy(z => z.Template.TemplateId)
                        .Select(grp => grp.First());

        return source;

    }