2016-12-06 63 views
0

下面是我的LINQ如何在此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>(); 

我得到的文檔名稱&業主在上面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

沒有看到你的模型,它是不是真的可以幫助你。我可以告訴的一件事是,您對編輯/審批者/審閱者的子查詢將嚴重低效。 – zaitsman

+0

@zaitsman,你能告訴我該如何改善? –

+0

@zaitsman,我已添加模型 –

回答

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(), 
+0

我已經試過這個&它也會返回文檔名稱,但是有些月份我需要類似的查詢,但是我使用'documents.Key'作爲它的一對一關係 –

相關問題