我正试图使用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 {
堆栈跟踪
- SPDataAccess_Lambda$__5(VB$AnonymousType_0`2$VB$It1,ListItem appWithSupport)
- System.Linq.d_31`3.MoveNext()
- System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable数据源,布尔数据绑定)
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"))
}