gpt4 book ai didi

c# - 包含的亚音速查询构造(Guid)

转载 作者:行者123 更新时间:2023-11-30 13:34:46 25 4
gpt4 key购买 nike

我有一个“注释”表。笔记支持一个级别的线程 - 换句话说,您可以回复一条笔记但不能回复另一个回复。所以表格看起来像下面这样:

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 事件记录来获取所有“父”注释:

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

我收到的错误是:“不支持‘包含’方法”有什么想法吗?

编辑:我尝试转换为如下字符串:

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

与之前相同的错误消息。

最佳答案

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

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

IEnumerable<string> noteListEnumerable = noteList;

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

关于c# - 包含的亚音速查询构造(Guid),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2073257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com