包含(Guid)的Subsonic查询构建

3

我有一个“笔记”表格。笔记支持一级线程 - 也就是说你可以回复一条笔记,但不能回复另一个回复。因此,该表格看起来像以下内容:

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
    )

我正在使用Subsonic active record获取所有“父”注释:

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

接下来,我只需要循环遍历IQueryable并填充一个笔记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

我收到的错误信息是:“不支持方法'Contains'”,有什么想法吗?
编辑:我尝试转换为以下字符串:
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); 

与之前相同的错误信息。

2个回答

10

看起来,Subsonic并不支持List<>.Contains。

但是,它支持IEnumerable<>.Contains,所以你可以尝试这个:

IEnumerable<string> noteListEnumerable = noteList;

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

1

我认为如果你将其设置为字符串,它应该可以工作 - Contains仅针对字符串值实现,但我知道我们已经使其工作。


尝试将所有内容转换为字符串(而不是Guid)- 仍然出现相同的错误消息。 - sestocker
Rob,请看一下我的回答,这似乎是List<>支持的问题,而不是Guids/字符串的问题。 - VladV
是的,我可以确认这一点,将列表转换回IEnumerable是可行的。 - dmose

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接