使用Visual Basic和Linq联接表时,将查询结果返回到ListView


你好,我似乎无法解决他的问题。我在ASP.Net WebForms应用程序中有一个ListView,我使用Model绑定来使用SelectMethod((获取数据。我有两个模型定义,下面列出,
Imports System.ComponentModel.DataAnnotations
Namespace Models
Public Class tblSizes_
    <Key>
    Public Property Series() As Integer
    Public Property Description() As String
    Public Property EDPNum() As String
    Public Overridable Property tblUSSeries() As ICollection(Of tblUSSeries)
End Class
End Namespace
Imports System.ComponentModel.DataAnnotations
Namespace Models
Public Class tblUSSeries
    <Key>
    Public Property Series() As Integer
    Public Property Description() As String
    Public Overridable Property tblSizes_() As ICollection(Of tblSizes_)
End Class
End Namespace

在我的GetSeries((方法中,我加入了tblSizes_表,因为我需要从其中的一些列中获取数据。我的方法发布在下面,

Public Function GetSeries(<QueryString("id")> searchString As String) As IQueryable(Of tblUSSeries)
    searchLabel.Text = searchString
    Dim pdb = New ProductDataContext()             
    Dim query As IQueryable(Of tblUSSeries) = 
                From a In pdb.tblUSSeries
                Join b In pdb.tblSizes_ On a.Series Equals b.Series
                Where a.Series.ToString().Equals(searchString) Or b.EDPNum.ToString().Equals(searchString)
                Select a
    Return query
End Function

我的问题是,在视图中,我可以从tblUSSeries表中获得这两个属性,但当我试图从tblSizes_表中添加一个属性时,我收到一个错误,说"EDPNum"不是"E.Model.tblUSSeries"的模因

<asp:ListView ID="seriesList" runat="server" DataKeyNames="Series" GroupItemCount="1" ItemType="E.Models.tblUSSeries" GroupPlaceholderID="groupPlaceholder1" ItemPlaceholderID="itemPlaceholder1" SelectMethod="GetSeries">
                        <EmptyDataTemplate>
                            <table id="emptyDataTable" runat="server">
                                <tr>
                                    <td>No data was returned.</td>
                                </tr>
                            </table>
                        </EmptyDataTemplate>
                        <EmptyItemTemplate>
                            <td id="emptyItemTable" runat="server" />
                        </EmptyItemTemplate>
                        <GroupTemplate>
                            <div style="clear: both">
                                <div id="itemPlaceholder1" runat="server">
                                </div>
                            </div>
                        </GroupTemplate>
                        <ItemTemplate>
                            <div style="width: 100%">
                                <div style="font-size: 12px; float: left; width: 50px; padding-bottom: 10px; color: green">
                                    <%#:Item.Series%>
                                </div>
                                <div style="font-size: 12px; font-family: Arial;  float: left; padding-right: 10px">
                                    <div >
                                        <%#:Item.Description%>
                                       </div>
                                </div>
                                <div style="font-size: 12px; font-family: Arial;  float: left; padding-right: 10px">
                                    <div >
                                        <%#:Item.EDPNum%>
                                    </div>
                                </div>
                            </div>
                        </ItemTemplate>

它需要实现Group Join来检索相关集合的层次模型

Public Function GetSeries(<QueryString("id")> searchString As String) As IQueryable(Of tblUSSeries)
    searchLabel.Text = searchString
    Dim pdb = New ProductDataContext()             
     Dim query As IQueryable(Of tblUSSeries) = 
            (From a In tblUSSeries
             Group Join b In tblSizes_ On a.Series Equals b.Series Into jTblSizes = Group
             Where a.Series.ToString().Equals(searchString) Or jTblSizes.Where(Function(p) p.EDPNum.ToString().Equals(searchString)).Any()
             Select New tblUSSeries With {.Series = a.Series, .Description = a.Description, .tblSizes_ = jTblSizes}
            ).AsQueryable().Cast(Of tblUSSeries)
    Return query
End Function

相关内容

  • 没有找到相关文章

最新更新