2011-03-03 55 views
0

我用EF4 EntityDataSources做成功的数据绑定,但在这里,我很为难的情况下:如何在EF4 EntityDataSource中获得下一级关联?

表“CurrentComplaintsByUsers”拥有的“投诉”表的外键。因此,在EF,我可以访问CurrentComplaintByUser记录,并导航到其父的投诉,像这样:

var ccU = dataContext.CurrentComplaintsByUsers.First(); 
var parentComplaint = ccU.Complaint; 

当我掀起基于CurrentComplaintsByUsers的EntityDataSource绑定一个gridview,我想从“投诉克服“反对称为”状态“的投诉协会。下面是我的投诉表StatusID,所以在代码中,我可以打投诉的状态,像这样,包括状态属性:

string statusLabel = parentComplaint.Status.LabelText; 

失败:当我尝试烤所有到EntityDataSource这个,我无法从我的起始条目“CurrentComplaintsByUsers”转到“状态”。这里是我的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,然后我得到一个NULL错误时它在我的Gridview中击中了..Complaint.Status.LabelText,几乎与你期望的一样。

回答

1

尝试在EntityDataSource

+0

AHHHH改变Include="Complaint, Status"Include="Complaint, Complaint.Status"。谢谢,你是个华丽的混蛋。完全有效。请注意,我HAATEE EF4需要阐明你的关系,而不是Linq-2-Sql的模式,根据需要应用它们。 – Graham 2011-03-03 18:00:45