確かに別の内部データソースを作成しましたが、別の問題が発生しました。Where 句を親のエンティティの ID に設定できませんでした。
FormView.DataItem にアクセスできないことに注意してください。フレンド クラスであり、アクセスできないタイプの EntityDataSourceWrapper です。
そこで、リフレクションで対処する関数を作成しました。
Microsoft のバグだと思います。修正されるまで、以下は、ネストされた EntityDataSource コントロールを使用するすべての人に役立つ可能性があります。
ここにあります:
Module Functions
Public Function GetEntity(Of TEntity As EntityObject)(ByVal entityDataSourceWrapper As Object) As TEntity
If entityDataSourceWrapper Is Nothing Then Return Nothing
Dim type = entityDataSourceWrapper.GetType()
If Not type.FullName = "System.Web.UI.WebControls.EntityDataSourceWrapper" Then Return Nothing
Dim wrapper = type.GetProperty("WrappedEntity", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance)
Return DirectCast(wrapper.GetValue(entityDataSourceWrapper, Nothing), TEntity)
End Function
End Module
コードビハインドでは、次のことを行います。
Protected Sub fvAccounts_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles fvAccounts.DataBound
If fvAccounts.CurrentMode <> FormViewMode.ReadOnly Then Exit Sub
Dim account As Account = GetEntity(Of Account)(fvAccounts.DataItem)
If account Is Nothing Then Exit Sub
Dim edsReports As EntityDataSource = fvAccounts.Row.FindControl("edsReports")
edsReports.Where = "it.Account.AccountId = " & account.AccountId
gvReports.DataBind()
End Sub
モデルの階層に注意してください。アカウントには多くのレポートがあります。