【发布时间】:2012-11-12 10:39:19
【问题描述】:
我已经尝试了所有的翻译服务来获得正确的语法,但我仍然得到“重载解析失败,因为无法使用这些参数调用任何可访问的 'SelectMany'” 在 select 语句的第一部分(直到 groupby 关键字之前的句号)
我试图在本地工作的在线示例中的原始 c# 语句:
public IEnumerable<TagGroup> GetTagGroups()
{
var tagGroups =
// extract the delimited tags string and session id from all sessions
DbSet.Select(s => new { s.Tags, s.Id })
.ToArray() // we'll process them in memory.
// split the "Tags" string into individual tags
// and flatten into {tag, id} pairs
.SelectMany(
s =>
s.Tags.Split(_tagDelimiter, StringSplitOptions.RemoveEmptyEntries)
.Select(t => new { Tag = t, s.Id })
)
// group {tag, id} by tag into unique {tag, [session-id-array]}
.GroupBy(g => g.Tag, data => data.Id)
// project the group into TagGroup instances
// ensuring that ids array in each array are unique
.Select(tg => new TagGroup
{
Tag = tg.Key,
Ids = tg.Distinct().ToArray(),
})
.OrderBy(tg => tg.Tag);
return tagGroups;
}
我在 VB 中最接近它:
Public Function GetTagGroups() As IEnumerable(Of TagGroup)
' extract the delimited tags string and session id from all sessions
' we'll process them in memory.
' split the "Tags" string into individual tags
' and flatten into {tag, id} pairs
' group {tag, id} by tag into unique {tag, [session-id-array]}
' project the group into TagGroup instances
' ensuring that ids array in each array are unique
Dim tagGroups = DbSet.[Select](Function(s) New With { _
s.Tags, _
s.Id _
}).ToArray().SelectMany(Function(s) s.Tags.Split(_tagDelimiter, StringSplitOptions.RemoveEmptyEntries).[Select](Function(t) New With { _
Key .Tag = t, _
s.Id _
})).GroupBy(Function(g) g.Tag, Function(data) data.Id).[Select](Function(tg) New With { _
Key .Tag = tg.Key, _
Key .Ids = tg.Distinct().ToArray() _
}).OrderBy(Function(tg) tg.Tag)
Return tagGroups
End Function
这会导致 Visual Studio 2012 intellisense 将语句的第一部分从第一行的“DbSet”到靠近底部的“.GroupBy”之前的最后一个括号用蓝色下划线。错误是“重载解析失败,因为无法使用这些参数调用可访问的 'SelectMany'”。
由于这是一个代码示例,我正在尝试转换为 vb 以在本地运行并理解,而我对 linq 的经验不足,我完全不知道如何尝试和处理这个问题。这超出了我目前的理解范围,因此可能是一个简单的语法错误或从头到尾的完整哈希!
非常感谢任何指点。
【问题讨论】:
标签: vb.net entity-framework linq