如何获取此LINQ中的Document名称?

时间:2016-12-06 09:04:01

标签: c# asp.net linq group-by

以下是我的LINQ

  IQueryable<DocumentMapper> query = (from c in entities.tTOCStructures
                                                    join e in entities.tUsers on c.CreatedBy equals e.UserUID
                                                    group c by c.FolderID into docs
                                                    where documentIds.Contains(docs.Key) 
                                                    select new DocumentMapper()
                                                    {
                                                         //DocumentName = Document Name
                                                        //Owner = e.FirstName + " " + e.LastName,
                                                        Editors = (from f in entities.tUsers join g in entities.tCheckoutViewUsers on f.UserUID equals g.ViewUserid where g.IsEditor == true && documentIds.Contains(g.DocumentID) select (f.FirstName + " " + f.LastName)),
                                                        Approvers = (from f in entities.tUsers join g in entities.tCheckoutViewUsers on f.UserUID equals g.ViewUserid where g.IsApprover == true && documentIds.Contains(g.DocumentID) select (f.FirstName + " " + f.LastName)),
                                                        Reviewers = (from f in entities.tUsers join g in entities.tCheckoutViewUsers on f.UserUID equals g.ViewUserid where g.IsReviewer == true && documentIds.Contains(g.DocumentID) select (f.FirstName + " " + f.LastName))
                                                    });
                documents = query.ToList<DocumentMapper>();

如何获取文档名称&amp;上面的LINQ中的所有者。

关系如下: -

  

一份文件将有一个文件名称和所有者,但多个编辑,审批,审稿人。

级别: -

 public class DocumentMapper
{
    public string DocumentName { get; set; }

    public string Owner { get; set; }

    public IEnumerable<string> Editors { get; set; }

    public IEnumerable<string> Reviewers { get; set; }

    public IEnumerable<string> Approvers { get; set; }

}

如果有任何关于改进这个LINQ的建议,我很乐意听到

1 个答案:

答案 0 :(得分:0)

我很猜测,但是在你的代码之后,你可能想要选择并选择第一项。除非(如上所述)你提供更多代码,否则我无能为力。

DocumentName = ((from f in entities.tUsers join g in entities.tCheckoutViewUsers on f.UserUID equals g.ViewUserid where g.IsEditor == true && documentIds.Contains(g.DocumentID) select (g.DocumentName)).First(),
相关问题