具有多个条件的组连接,其中一个条件是常数
这是我的 (VB) LINQ 的片段:
From event_evn In xmlEvents.Descendants("event_evn") _
Join genre_gnr In xmlGenre.Descendants("genre_gnr") On event_evn.Element("evn_gnr_id") Equals genre_gnr.Element("gnr_id").Value _
Group Join eventdata_eda In xmlEventData.Descendants("eventdata_eda") On _
eventdata_eda.Element("eda_evn_id").Value Equals event_evn.Element("evn_id").Value And _
eventdata_eda.Element("eda_dty_id").Value Equals "15" _
Into edaList = Group _
From eventdata_eda In edaList.DefaultIfEmpty() _
Where _
我在最后一行收到一条错误消息: “您必须在‘等于’运算符两侧至少引用一个范围变量” 如何进行具有多个条件的组连接,其中其中一个条件是与常量进行比较?
我找到了两个有答案的地方:
http://forums.asp.net/p/1209451/2127071.aspx# 2127071
LINQ to SQL - 具有多个连接条件的左外连接< /a>
但是它是 C# 语言的,我需要 VB 语言的。
提前致谢 :)
Here is a snippet of my (VB) LINQ:
From event_evn In xmlEvents.Descendants("event_evn") _
Join genre_gnr In xmlGenre.Descendants("genre_gnr") On event_evn.Element("evn_gnr_id") Equals genre_gnr.Element("gnr_id").Value _
Group Join eventdata_eda In xmlEventData.Descendants("eventdata_eda") On _
eventdata_eda.Element("eda_evn_id").Value Equals event_evn.Element("evn_id").Value And _
eventdata_eda.Element("eda_dty_id").Value Equals "15" _
Into edaList = Group _
From eventdata_eda In edaList.DefaultIfEmpty() _
Where _
I get an error in the last line with this message:
"You must reference at least one range variable on both sides of the 'Equals' operator"
How do I do a group join with multiple conditions, where one of these conditions is to comparing with a constant?
I found two places with the answer:
http://forums.asp.net/p/1209451/2127071.aspx#2127071
LINQ to SQL - Left Outer Join with multiple join conditions
However it is both in C# and I need it in VB.
Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最近遇到了一个类似的问题,我可以通过在 LINQ 查询中声明一个匿名类型的变量来保存我想要连接的所有值,并在连接条件中使用该新的临时变量来解决这个问题,这样您的代码片段如下所示:
I had a similiar issue recently and I was able to get around it by declaring a variable of an anonymous type within the LINQ query to hold all the values I wanted to join on, and to use that new temporary variable in the join conditions so your snippet would look something like below:
为了左连接常量值,我添加了以下内容:
使用 LinqPad 我检查并生成了预期的 SQL。
To left join on a constant value I added the the following:
Using LinqPad I checked and the expected SQL is generated.