3

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.

sestocker
  • 3,522
  • 6
  • 27
  • 32

2 Answers2

10

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
  • 10,093
  • 3
  • 32
  • 48
1

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.