VB.NET 使用查询语法的 Linq 左连接

VB.NET Linq Left Join using Query Syntax

我有一个应用程序列表。每个应用程序可能有也可能没有与之关联的支持记录。

我能加入的唯一方法是获取 App Title 并查看它是否等于 Support(Product) 的 LookupValue。但要获得 属性,我必须转换为 FieldLookupValue。当没有关联的支持记录时,这就是在 Linq 查询中的 .MoveNext() 上引发空引用错误的地方。以下是当前适用于具有关联支持的应用程序的方法,但如果不支持则抛出错误。

Dim q =
    From a In apps.AsEnumerable()
    Group Join s In support.AsEnumerable()
    On a("Title").ToString() Equals CType(s("Product"), FieldLookupValue).LookupValue 
    Into Group
    From ajs In Group.DefaultIfEmpty()
    Select New With {
        .Name = a("Title"),
        .SupportEnd = IIf(ajs Is Nothing, Nothing, ajs("End"))
    }

有什么方法可以比较 On 语句中的匿名类型?我似乎无法获得正确的语法,或者它可能是不可能的。我觉得这可以修复空引用错误。我不成功的尝试返回 Equals cannot compare type with the value of type

Dim q =
   From a In apps.AsEnumerable()
   Group Join s In support.AsEnumerable()
   On
   (New With {Key .AppName = a("Title").ToString()}) Equals
   (New With {Key .AppName = IIf(s Is Nothing, "nada", CType(s("Product"), FieldLookupValue).LookupValue)})
   Into Group
   From ajs In Group.DefaultIfEmpty()
   Select New With {
      .Name = a("Title"),
      .SupportEnd = IIf(ajs("End") Is Nothing, Nothing, ajs("End"))
   }

任何有关如何使用上述两种失败方法之一使此连接正常工作的想法都很好。

一旦我根据支持列表中的随机选择(我选择了索引 0)创建了一个虚拟默认对象,我就用它来进行比较,如图所示。然后只需使用 Let 语句即可在选择时轻松访问布尔值。

Dim q =
    From a In apps.AsEnumerable()
    Group Join s In support.AsEnumerable()
    On a("Title").ToString() Equals CType(s("Product"), FieldLookupValue).LookupValue 
    Into Group
    From ajs In Group.DefaultIfEmpty(support(0))
    Let NoSupport As Boolean = IIf(ajs.Equals(support(0)), True, False)
    Select New With {
        .Name = a("Title"),
        .SupportEnd = IIf(NoSupport, "No Support", ajs("End"))
    }