此提供程序仅支持跳过有序查询吗?

时间:2013-01-09 15:35:35

标签: vb.net linq-to-sql

我收到以下错误消息... 此提供程序仅支持跳过返回包含所有标识列的实体或投影的有序查询,其中查询是单表(非连接)查询,或者是Distinct,Except,Intersect或Union(非Concat)操作。

  <asp:DropDownList ID="ddlModels" runat="server" 
                          DataSourceID="ldsListOfModelNos" 
                          DataTextField="EngineModel" 
                          DataValueField="EngineModel" 
                          AppendDataBoundItems="True" 
                          AutoPostBack="true">
      </asp:DropDownList>

       <br/>

       <br />

       <asp:LinqDataSource ID="ldsListOfModelNos" 
                          runat="server" >                              
      </asp:LinqDataSource>


 <asp:GridView ID="gvPriceListByModel" runat="server" EmptyDataText="No Price Info Available"                                                   AutoGenerateColumns="False" CellPadding="4" CellSpacing="4" ForeColor="#333333" GridLines="None" AllowPaging="True"                                             DataSourceID="ldsPBM2" DataKeyNames="EngineSpec">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <Columns>
                 <asp:BoundField DataField="EngineModel" HeaderText="EngineModel" 
                      Visible="False" />
                 <asp:BoundField DataField="EngineSpec" HeaderText="ItemNo"  />
                 <asp:BoundField DataField="NewOrRebuilt" HeaderText="NR" Visible="False" />
                 <asp:BoundField ConvertEmptyStringToNull="False" DataField="RetailPrice" 
                      DataFormatString="{0:c}" HeaderText="Retail Price" />
                 <asp:BoundField DataField="DistributorPrice" DataFormatString="{0:c}" 
                      HeaderText="Distributor Price" />
                 <asp:BoundField DataField="CorePrice" DataFormatString="{0:c}" 
                      HeaderText="Core Price" />
            </Columns>
            <EditRowStyle BackColor="#999999" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#E9E7E2" />
            <SortedAscendingHeaderStyle BackColor="#506C8C" />
            <SortedDescendingCellStyle BackColor="#FFFDF8" />
            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />

       </asp:GridView>


          

Protected Sub ldsPriceListByModel2_Selecting(sender As Object, e As  System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles ldsPriceListByModel2.Selecting
      If Not IsPostBack Then
           Dim sd As SessionData = Session("SessionData")
           sd.CmpCode = "95102"
           Dim cmpCode = sd.CmpCode
           Dim interimResult = dataUtil.GetQueryablePriceList(cmpCode)

           e.Result = interimResult.Where(Function(m) m.EngineModel = ddlModels.SelectedValue).OrderBy(Function(o) o.EngineSpec)
      End If

 End Sub

                Public Class DataUtils

                Private dc As DataAccess

                 Public Function GetQueryablePriceList(cmpCode As String) As IQueryable(Of PriceInfo)

  dc = New DataAccessClass(ConfigurationManager.ConnectionStrings("xxx").ConnectionString.ToString())

      Dim PriceListQuery = (From ms In dc.dbo.v_ModelSpecs
              Join pl In dc.dbo.v_pricelists
              On ms.item_no Equals pl.item_no
              Join ci In dc.dbo.cxabcx_VWs
              On pl.accounttypecode Equals ci.AccountTypeCode
              Where (pl.price <> 0 And ci.cmp_code = cmpCode)
          Select New PriceInfo() With {.EngineModel = ms.Model,
                                       .EngineSpec = ms.item_no,
                                       .NewOrRebuilt = IIf(pl.item_desc_1 = "ENGINE - NEW", "N", "R"),
                                       .RetailPrice = pl.price, .DistributorPrice = pl.disc_price,  .CorePrice = pl.sls_price}).AsQueryable()

      Return PriceListQuery
 End Function

Public Class PriceInfo

 Public Sub New()

 End Sub

 Public Property EngineModel As String

 Public Property EngineSpec As String

 Public Property NewOrRebuilt As Char

 Public Property RetailPrice As Decimal

 Public Property DistributorPrice As Decimal

 Public Property CorePrice As Decimal

End Class

这是一个经典的一对多场景,一个引擎模型很多引擎规格...... gridview由下拉列表中的键选择驱动(ddlModels)。选择引擎模型,您可以在gridview表中获取价目表详细信息。我的LINQ查询在名为DataUtils的数据访问类中被隔离。在LINQDATASOURCE(lds)的选择事件中,我将e.Results属性分配给初始查询的结果,但是已经由最终用户通过ddlModels选择的EngineModel对其进行过滤(WHERE)。 gridview只允许Pagin启用NOT SORTING。为什么我会收到此错误消息?

2 个答案:

答案 0 :(得分:1)

简短的回答是,您似乎遇到了linqdatasource对象的限制。您可能需要尝试手动绑定而不使用数据源。在大多数情况下,我经常避免使用LinqDataSource,除非我只处理简单的平面表映射。

或者,您可以尝试将该属性添加到PriceInfo对象定义中的列,但此选项未经测试。

您可以查看此搜索中各种论坛帖子中的建议:http://www.bing.com/search?q=%22This+provider+supports+Skip+only+over+ordered+queries+returning+entities+or+projections+that+contain+all+identity+columns%22&qs=n&form=QBRE&pq=%22this+provider+supports+skip+only+over+ordered+queries+returning+entities+or+projections+that+contain+all+identity+columns%22&sc=0-0&sp=-1&sk=

答案 1 :(得分:1)

我将使用参数化的存储过程替换此Linq to SQL查询以检索数据。由于SP可以在视图中查询数据,因此它应该可以工作。

或者将DevExpress放在一起