2010-01-15 78 views
3

我有一個「註釋」表。 Notes支持一種線程級別 - 換句話說,您可以回覆註釋但不能回覆其他回覆。所以表看起來像下面這樣:Subsonic查詢構建包含(Guid)

CREATE TABLE [dbo].[Notes] (
[NoteId] [uniqueidentifier] ROWGUIDCOL NOT NULL DEFAULT (newid()) 
    CONSTRAINT [PK__Notes] 
    PRIMARY KEY ([NoteId]), 
[ParentNoteId] UNIQUEIDENTIFIER NULL, 
[NoteText] NVARCHAR(MAX) NOT NULL, 
[NoteDate] DATETIME NOT NULL 
    ) 

所以我用亞音速活動記錄讓所有的「父」註釋:通過IQueryable的

var allNotes = (from n in Note.All() 
         where n.ParentNoteId == null 
         orderby n.NoteDate descending 
         select n) 
         .Skip((pageIndex - 1) * pageSize).Take(pageSize); 

接下來,我只是循環,並填寫通用筆記的GUID列表:

List<Guid> noteList = new List<Guid>(); 
foreach (var note in allNotes) 
{ 
    noteList.Add(note.NoteId); 
} 

最後,我要建一個查詢來獲取所有的回覆來自原始查詢說明:

replies = from n in Note.All() 
      where n.ParentNoteId != null && noteList.Contains(n.ParentNoteId.Value) 
      select n 

我收到的錯誤是:「方法‘包含’不支持」任何想法?

編輯:我試圖轉換爲字符串如下所示:如前所述

List<String> noteList = new List<String>(); 
foreach (var note in allNotes) 
{ 
    noteList.Add(note.NoteId.ToString()); 
} 
replies = (from n in Note.All() 
      where n.ParentNoteId != null && 
      noteList.Contains(n.ParentNoteId.Value.ToString()) select n); 

相同的錯誤消息。

回答

10

看來,列表<> .Contains不被Subsonic支持。

但是,IEnumerable的<>。載有支持,所以你可以試試這個:

IEnumerable<string> noteListEnumerable = noteList; 

replies = from n in Note.All() 
      where n.ParentNoteId != null && noteListEnumerable.Contains(n.ParentNoteId.Value) 
      select n 
+0

IEnumerable工作。謝謝您的幫助。 – sestocker 2010-01-18 14:22:29

1

我覺得如果你設置爲一個字符串,它應該工作 - 包括只對字符串值實現,但我知道,我們確實有這方面的工作。

+0

試圖將所有爲字符串(而不是GUID) - 仍是同樣的錯誤消息。 – sestocker 2010-01-15 19:16:05

+0

Rob,請看看我的答案 - 看起來,List <>支持存在問題,而不是Guids/strings。 – VladV 2010-01-18 16:41:20

+0

是的,我可以證實這一點,把一個列表放回到IEnumrable作品 – dmose 2010-03-10 16:32:12