如何将实体数据源绑定到查询结果 [英] How can I bind an entity Data Source to the results of a query
本文介绍了如何将实体数据源绑定到查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个查询,它将消失并查找数据
I have a query that will go away an and find data
Dim HSNs As String = String.Join(",", ListOfHSNs.Cast(Of String)().ToArray())
Dim query As String = "SELECT VALUE O FROM v_BillData AS O WHERE O.HSNumber IN {'" & HSNs & "'}"
Dim hs As New ObjectQuery(Of v_BillData)(query, CType(Session("ObjectCon"), ObjectContext))
我现在要做的是使用此查询的结果将数据绑定到EntityDataSource
我该怎么办
what I now wish to do is to use the results of this query to databind to a EntityDataSource How can I do this?
推荐答案
您可以尝试使用Selecting EntityDataSource事件,如以下示例所示:
You can try to use the Selecting EntityDataSource event like in the following example:
Protected Sub EntityDataSource1_Selecting(ByVal sender As Object, ByVal e As EntityDataSourceSelectingEventArgs)
Dim HSNs As String = String.Join(",", ListOfHSNs.Cast(Of String)().ToArray())
Dim query As String = "SELECT VALUE O FROM v_BillData AS O WHERE O.HSNumber IN {'" & HSNs & "'}"
Dim source As EntityDataSource = Nothing
source = TryCast(Me.Page.FindControl("EntityDataSource1"),EntityDataSource)
If (Not source Is Nothing) Then
source.EntitySetName = Nothing
source.CommandText = query
End If
End Sub
您应该将EntitySetName设置为Nothing,因为如果您设置了EntityDataSource,它将抛出错误之前。
You should set EntitySetName to Nothing because it will throw an error if you have setup EntityDataSource before.
这篇关于如何将实体数据源绑定到查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文