Contains 的 Subsonic 查询构造(Guid)

发布于 2024-08-17 19:55:39 字数 1463 浏览 8 评论 0原文

我有一个“注释”表。注释支持一级线程 - 换句话说,您可以回复注释,但不能回复另一个回复。因此,该表如下所示:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静待花开 2024-08-24 19:55:39

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

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
您的好友蓝忘机已上羡 2024-08-24 19:55:39

我认为如果你设置为一个字符串,它应该可以工作 - 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文