如何将存储在会话变量中的对象的属性用作EntityDataSource中的WhereParameter



早上好
我正在使用EntityDataSource,并希望使用WhereParameter对其进行筛选,该WhereParameters是存储在会话变量session("Ticket"(中的对象的属性。这可能吗?

这是我用于Ticket对象的类,它被存储到会话变量中

Partial Public Class TICKET
Private _ID As Integer              '-- I want to use the property "ID" as the parameter
Private _Category As String     
Private _Status As String
Private _Priority As String
...
...
End Class

这里有一些标记,但不确定如何获得属性";ID";作为参数

<asp:EntityDataSource ID="edsDBase" runat="server"  AutoGenerateWhereClause="True"
ConnectionString="name=edsDBContainer"
DefaultContainerName="edsDBContainer" EnableFlattening="False"
EntitySetName="edsTicket" EnableDelete="True" EnableInsert="True"
EnableUpdate="True" EntityTypeFilter="tbICObjectBase">
<WhereParameters>
<asp:SessionParameter SessionField="Ticket.ID (this is what I'd like to do)" Name="TicketID" Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>

我还尝试通过EntityDataSource的OnSelecting事件以编程方式执行此操作,但也对此感到困惑。

Protected Sub edsTickets_OnSelecting(sender As Object, e As EntityDataSourceSelectingEventArgs)
Dim eds As EntityDataSource = CType(sender, EntityDataSource)
Dim ticket As V_TICKETS = Session("Ticket")
Dim xparam As New Parameter("ID", DbType.Int32)
xparam.DefaultValue = ticket.ID
eds.WhereParameters.Add(xparam)
End Sub

但这引发了一个异常,表示我无法将EntityDataSourceView强制转换为EntityDataSource。有人能帮我解决这个问题吗?非常感谢。

通过处理EntityDataSource中的OnSelecting事件解决了我的问题。

Protected Sub edsTickets_OnSelecting(sender As Object, e As EntityDataSourceSelectingEventArgs)
Dim eds As EntityDataSource = e.DataSource 'As suggested by G3nt_M3caj on Jun 1 at 16:29. Thanks again!
Dim ticket As V_TICKETS = Session("Ticket")
Dim xparam As New Parameter("ID", DbType.Int32)
xparam.DefaultValue = ticket.ID
eds.WhereParameters.Add(xparam)
End Sub

相关内容

  • 没有找到相关文章

最新更新