如何使用存储在会话变量中的对象的 属性 作为 EntityDataSource 中的 WhereParameter?
How can I use the property of an object stored in a session variable as a WhereParameter in an EntityDataSource?
早上好!
我正在使用 EntityDataSource 并希望使用 WhereParameter 对其进行过滤,该 WhereParameter 是存储在会话变量 Session("Ticket") 中的对象的 属性。这可能吗?
这是我用于存储到会话变量中的 Ticket 对象的 class
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
早上好!
我正在使用 EntityDataSource 并希望使用 WhereParameter 对其进行过滤,该 WhereParameter 是存储在会话变量 Session("Ticket") 中的对象的 属性。这可能吗?
这是我用于存储到会话变量中的 Ticket 对象的 class
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