EF4 EntityDataSourcesを使用してDataBindingを成功させましたが、困惑した場合は次のようになります。
テーブル「CurrentComplaintsByUsers」には、「Complaints」テーブルへの外部キーがあります。したがって、EFでは、CurrentComplaintByUserレコードにアクセスし、次のようにその親の苦情に移動できます。
var ccU = dataContext.CurrentComplaintsByUsers.First();
var parentComplaint = ccU.Complaint;
CurrentComplaintsByUsersに基づいてEntityDataSourceを作成してグリッドビューをバインドするとき、「Complaint」オブジェクトから「Status」と呼ばれるAssocationofComplaintに移動したいと思います。これが私の苦情テーブルのStatusIDです。したがって、コードでは、Statusプロパティを含め、苦情のステータスを次のようにヒットできます。
string statusLabel = parentComplaint.Status.LabelText;
失敗:これをすべてEntityDataSourceにベイクしようとすると、開始アイテム「CurrentComplaintsByUsers」から「Status」に移動できません。これが私のEDSです:
<asp:EntityDataSource ID="edsCurrentCases" runat="server"
ConnectionString="name=EOCaseDataModel" DefaultContainerName="EOCaseDataModel"
EnableFlattening="False" EntitySetName="CurrentComplaintsByUsers"
Include="Complaint, Status">
</asp:EntityDataSource>
私のエラーはこれです:
System.InvalidOperationException
"A specified Include path is not valid.
The EntityType 'EOCaseApp.CurrentComplaintsByUser' does not declare a navigation property with the name 'Status'."
私はこれが私のGridviewで機能するポイントに到達しようとしています:
<%# ((CurrentComplaintsByUser)Container.DataItem).Complaint.Status.LabelText %>
したがって、宣言的マークアップのみを使用して、EDSから関連するオブジェクトの関連付けを取得するにはどうすればよいですか?(コードでそれを行うことができます。可能な場合はEDSを排他的に使用しようとします)
その他の注意事項:EDSの「インクルード」から「ステータス」を削除すると、Gridviewの..Complaint.Status.LabelTextにヒットしたときにNULLエラーが発生します。これは、ほぼ期待どおりです。