views:

171

answers:

2

I have a "Notes" table. Notes support one level of threading - in other words you can reply to a note but cannot reply to another reply. So the table looks something like the following:

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
    )

So I am using Subsonic active record to get all the "parent" notes:

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

Next I just loop through the IQueryable and fill a generic list of the note Guids:

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

Finally, I am trying to construct a query to get all the replies to notes from the original query:

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

The error I am receiving is: "The method 'Contains' is not supported" Any ideas?

EDIT: I tried converting to strings like the following:

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); 

Same error message as before.

+1  A: 

I think if you set to a string it should work - Contains is only implemented for string values but I know we do have this working.

Rob Conery
Tried converting all to strings (instead of Guid) - still the same error message.
sestocker
Rob, have a look at my answer, please - it seems, there is a problem with List<> support, not with Guids/strings.
VladV
Yeah I can confirm this, casting a list back down to IEnumrable works
dmose
+4  A: 

It seems, List<>.Contains is not supported by Subsonic.

However, IEnumerable<>.Contains is supported, so you could try this:

IEnumerable<string> noteListEnumerable = noteList;

replies = from n in Note.All()
          where n.ParentNoteId != null && noteListEnumerable.Contains(n.ParentNoteId.Value)
          select n
VladV
IEnumerable worked. Thanks for the help.
sestocker