Linq Left Join VB.NET 到匿名类型列表

Linq Left Join VB.NET To Anonymous Typed List

我正在尝试使用 Linq 在数据为 Microsoft.SharePoint.Client.ListItem 的匿名类型对象列表上完成 LEFT OUTER JOIN 我想显示所有应用程序。任何 具有 相关支持记录的应用程序,我都会显示这些属性。任何 没有 关联支持记录的应用程序,我会将这些字段显示为空。

更新 - 下面的代码适用于返回的第一个应用程序,它有关联的支持,但在列表中的下一个没有关联支持的应用程序上抛出错误.我很困惑为什么我在枚举的 .MoveNext() 期间遇到空引用错误。任何帮助将非常感激。

LINQ + 数据绑定

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, "Unsupported", ajs("End"))
  }

gvApps.DataSource = q.AsQueryable()
gvApps.DataBind()

显示

<asp:GridView ID="gvApps" runat="server" CssClass="GvApps"
         AutoGenerateColumns="false" EnableViewState="true"
         GridLines="None" CellSpacing="-1">
      <Columns>
        <asp:TemplateField HeaderText="Application">
          <ItemTemplate>
            <%# DataBinder.Eval(Container.DataItem, "Name")%>
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Support End">
          <ItemTemplate>
            <%# DataBinder.Eval(Container.DataItem, "SupportEnd")%>
          </ItemTemplate>
        </asp:TemplateField>
      </Columns>
</asp:GridView>

错误

对象引用未设置为对象的实例。 Select New With {

堆栈跟踪

            Dim AppsList =
            From a In applications.AsEnumerable()
            Group Join s In support.AsEnumerable()
            On Integer.Parse(a("ID")) Equals CType(s("Product"), FieldLookupValue).LookupId Into Group
            From appSupport In Group.DefaultIfEmpty()
            Order By a("Title") Ascending
            Select New With {
                .AppID = a("ID"),
                .AppViewUrl = AppSettings("ViewURL") & "&ListId={" & AppSettings("AppListGuid") & "}&ID=" & a("ID"),
                .AppName = a("Title"),
                .AppContact = ParseMultivaluedUser(a("App_x0020_Contact"), "No Contacts Listed"),
                .SupportEnd = If(appSupport IsNot Nothing AndAlso Date.TryParse(appSupport.Item("End"), New Date), Date.Parse(appSupport.Item("End")).ToShortDateString, Nothing),
                .Licenses = If(appSupport Is Nothing, Nothing, appSupport.Item("Quantity")),
                .StatusIcon = If(appSupport IsNot Nothing, GetStatusIcon(appSupport.Item("End")), "<span class=""StatusIco Tip NoSupport"" title=""No Support Record""> </span>"),
                .SupportTitle = If(appSupport Is Nothing, Nothing, appSupport("Title")),
                .AkaNames = a("AKA_x0020_Names"),
                .AkaOmit = a("AKA_x0020_Omit"),
                .Installs = GetInstalls(a("ID"), a("AKA_x0020_Names"), a("AKA_x0020_Omit"))
            }