Contains 的 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
)
因此,我使用 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 并填充音符 Guids 的通用列表:
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);
与以前相同的错误消息。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Subsonic 似乎不支持 List<>.Contains。
但是,支持 IEnumerable<>.Contains,因此您可以尝试以下操作:
It seems, List<>.Contains is not supported by Subsonic.
However, IEnumerable<>.Contains is supported, so you could try this:
我认为如果你设置为一个字符串,它应该可以工作 - Contains 仅针对字符串值实现,但我知道我们确实有这个工作。
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.