Good morning!
I am using an EntityDataSource and would like to filter it with a WhereParameter that is a property of a object stored in a session variable, Session("Ticket"). Is this possible?
Here's the class I use for a Ticket object that gets stored into a session variable
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
and here is some markup, but not sure how to get the property "ID" in as the parameter
<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>
I also tried doing it programmatically through the OnSelecting event of the EntityDataSource but got confused on that, too.
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
But this threw an exception saying I cannot cast an EntityDataSourceView to an EntityDataSource. Anyone able to help me straighten this out? Thank you!
My problem was solved by handling the OnSelecting event from the EntityDataSource.
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